Sunday 15 April 2012

c - What happens after the parent of zombie process terminates? -


I'm just curious, what happens to the zombie process, if his parents do not wait for it

Suppose, our parents and children are finished before the parents

From AE:

The kernel for every elimination process Minor information keeps ... Minimal - Process ID, Termination status >

Interpretation is:

Does the kernel removes this information (of course it is no use)? Alternatively, does it collect this junk? Is this implementation specific? Is there a standard way to deal with this situation?

Orphaned processes are automatically adopted by init , in which one Standard SIGCHLD handler that rejects any exit status of a dead process.

In your case if zombie orphan dies of zombie procedure then zombie orphan will be adopted by intrusion and will be cleaned.

The following code checks it out:

  #include & lt; Stdlib.h & gt; # Include & lt; Stdio.h & gt; # Include & lt; Unistd.h & gt; Int main () {pid_t child_pid; If (child_pid = fork ()) {// a child's fork, then the child will go straight out of the name [128]; Sprintf (name, "/ proc /% d / stat", child_pid); Four line [2048]; // read child / proc / pid / stat, field 3 will give its status FILE * fp = fopen (name, "r"); Whereas (fgets (line, shape, line FP)) (line); Fclose (fp); Usleep (5000000); // will go out to ensure the child till now, repeat fp = fopen (name, "r"); Whereas (fgets (line, shape, line FP)) (line); Fclose (fp); // If any other child has to repeat the procedure and get out of the parent (! Fork ()) {sleep (5000000); // Both parent and child will both exit now fp = fopen (name, "r"); // This should fail because init has already cleared the child if (! Fp) {perror ("fopen"); Return -1; } While (fgets (line, size, line FP)) (line); Fclose (fp); }} Return 0; }    

No comments:

Post a Comment