How do you create a zombie process?

I'm very new to UNIX, so I need some help please.

How do I create a zombie process with just basic UNIX commands (no script, C, PERL, etc)? Please give an example. Thanks.

you don't create zombie processes. zombie is a process state. the process does not actually exist. Read up on what a zombie process is and then you will understand how to do it. I don't understand why a UNIX newbie would be trying to do this though.

I know zombie is a process state, but I'm trying to create one so I can see how it looks like.

this sounds cool.
so teiji.
did u get a chance to see a ZOMBIE process?
If yes, please reply me your work and if possible an example !!!

Hello,

A ZOMBIE program is NOT something you want in your system.

It is a process that crashed and which is robbing memory space and/or cpu cycles.
They are detached from any terminals or processes that lauched it in the first place and are hard to kill. sometime only a reboot can get rid of it.

However, if you want to launch a program in the background there is 2 options to do so.

A) /usr/bin/your program &
B) nohup /usr/bin/your program

The differences lies in what your program do when you log out.
A) The program terminates upon login out
B) The program keep on running and only a kill or fuser command will stop it.

If you're curious and want to see how a zombie looks like you can create a zombie process with this c program:

#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main ()
{
  pid_t child_pid;

  child_pid = fork ();
  if (child_pid > 0) {
    sleep (60);
  }
  else {
    exit (0);
  }
  return 0;
}

Save it as zombie.c, compile it with:

cc zombie.c -o zombie

and run it with:

./zombie

Now check the output of this command (within 1 minute) in another window:

ps -e -o pid,ppid,stat,cmd

The child process is marked as <defunct>, and its status code is Z, for zombie.

When the program exits, the child process is inherited by init. This process should cleans up the zombie proces automatically.

Regards

this is an incorrect statement. a zombie process is not taking up system resources. the process does not actually exist anymore. the entry is left in the process table until the parent reads its exit status. The only resource used is the slot in the process table.