lost and found ( for me ? )

C programming : how to create a zombie process



# gcc --version | head -1
gcc (GCC) 4.4.6 20120305 (Red Hat 4.4.6-4)

# cat /etc/centos-release
CentOS release 6.3 (Final)

# uname -ri
2.6.32-279.1.1.el6.i686 i386

# cat create-zombie.c -n
    1  #include <stdio.h>
    2  #include <sys/types.h>
    3  #include <unistd.h>
    4  #include <stdlib.h>
    5
    6  int main()
    7  {
    8          pid_t c_pid;
    9
   10          c_pid=fork(); /* crete a child process */
   11
   12          if (c_pid > 0) { /* child process */
   13                  printf("Parent PID : %d\r\n", getpid());
   14                  printf("Child PID  %d is zombie process \r\n", c_pid);
   15                  sleep (1000);
   16          }
   17          else {
   18                  return 0;
   19          }
   20  return 0;
   21  }

compile it.

# gcc create-zombie.c -o create-zombie.o

run
# ./create-zombie.o
Parent PID : 1688
Child PID 1689 is zombie process

check whether or not child process is zombie.

# pstree -p 1688
create-zombie.o(1688)---create-zombie.o(1689)

PID 1689 is marked as a zombie process.

# ps aux | awk '{ print $8 " " $2 }' | grep -w Z
Z+ 1689

# top -b -n 1
top - 20:43:31 up 28 min,  2 users,  load average: 0.00, 0.00, 0.00
Tasks: 100 total,   1 running,  98 sleeping,   0 stopped,   1 zombie

# egrep -i state /proc/1689/status
State:  Z (zombie)

1 comment:

  1. Hey admin,
    of course this blog is doing a very good job of serving useful information. I'm proud to be a part of its Readers community.
    for more programing visit my web
    http://www.hhhprogram.com/

    ReplyDelete

Note: Only a member of this blog may post a comment.