Quoting Andrew Guertin <[log in to unmask]>:
> Thought people might appreciate this little Zombie Jesus Day themed C
> program I wrote:
>
> http://blog.dolphinling.net/2009/04/happy-zombie-jesus-day/
Andrew Guertin wrote:
> Thought people might appreciate this little Zombie Jesus Day themed
> C program I wrote:
>
> http://blog.dolphinling.net/2009/04/happy-zombie-jesus-day/
For those who are curious, this "Zombie Jesus" program does a little
trick called forking. When a process forks, it creates a copy of
itself. This is easily done by calling the fork() system call, which
returns a process id as an integer. The new process is the "child
process" and the old one is the "parent process."
After calling fork(), both processes resume their execution like
nothing happened. But the child process knows it's a child process,
and the parent process realizes it's a parent, depending on the return
value of fork(). So the processes can do different things. It's kind
of like cloning Dolly and giving Dolly #2 a kick.
Anyway, the joke is that Jesus fork()s and becomes God, and when God
goes away, Jesus becomes a zombie. When a child process wants to
terminate, it becomes a zombie if the parent is waiting or already
terminated.
As for the program itself, changing argv[0] is a little sketchy
because of the possibility of a buffer overrun. There are very few
legitimate uses for it that I can think of. I would be curious to
know if there is actually a system call that can change the process
name (or rather, the command argument from exec(), which is what shows
up in argv[0]).
A minor change:
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char **argv)
{
pid_t pid;
pid = fork();
if (pid > 0) {
strncpy(argv[0], "god", strlen(argv[0]));
sleep(30);
}
return 0;
}
|