| elsiddik 2007-04-24, 4:07 am |
| On Apr 24, 2:51 pm, Hubble <rei...@huober.de> wrote:
> On 24 Apr., 06:16, djh...@gmail.com wrote:
>
>
>
> Yes. The Zombie Processes (state Z) occupy space in the process table.
> The easiest way to solve this is to use double forking:
> pid1=fork();
> if (pid1==0) { /* son */
> pid2=fork();
> if (pid2==0) /* son of son */
> { do_work();
> _exit(0);
> }
> /* son */
> _exit(0);
> }
> /* parent, error checking pid<0 */
> wait(&status);
>
> Here, parent can wait since its son exists immediately after creating
> his own son. Init process takes care of sons son after son has exited.
>
> Hubble.
or create a signal handler to catch SIG_CHLD and call wait within the
handler to prevent childrens to become zombies -- zombies can cause ur
system to run out of prossesses,
sig_chld(int signo)
{pid_t pid;
int stat;
pid = wait(&stat);
}
cheers,
zaher el siddik
http://elsiddik.blogspot.com/
|