Linux fork - execl, executable process becomes zombie

I am trying to run the twinkle command line from a child process. For example, for example:

int hangup() { write_on_display("line3", " "); write_on_display("hide_icon", "DIALTONE"); write_on_display("hide_icon", "BACKLIGHT"); int pid = fork(); if (pid == 0) { int res = execl("/usr/bin/twinkle", " ", "--immediate", "--cmd", "answerbye", (char *) NULL); _exit(0); } else { perror("hangup"); return 0; } return 1; } 

but the flicker becomes a zombie:

 10020 pts/1 Z+ 0:00 [twinkle] <defunct> 10040 pts/1 Z+ 0:00 [twinkle] <defunct> 10053 pts/1 Z+ 0:00 [twinkle] <defunct> 10064 pts/1 Z+ 0:00 [twinkle] <defunct> 10097 pts/1 Z+ 0:00 [twinkle] <defunct> 10108 pts/1 Z+ 0:00 [twinkle] <defunct> 10130 pts/1 Z+ 0:00 [twinkle] <defunct> 

I tried to set the signal (SIGCHLD, SIG_IGN); but unsuccessfully. In fact, I think the baby process is dying before the shine ends.

Flickering from the command line, for example:

 twinkle --immediate --call 100 

doesn't make zombies - the flicker closes properly. What am I missing there?

+4
source share
2 answers

The parent process should call waitpid() with the process ID of the child. On the link page:

All these system calls are used to wait for state changes in the child process of the calling process and to receive information about the child whose state has changed. A change in state is considered: the child is terminated; the child was stopped by a signal; or the child has been resumed by a signal. In the case of a completed child, fulfilling the expectation allows the system to free resources associated with the child; if the expectation is not fulfilled, then the completed child remains in a "zombie" state (see NOTES below).

For instance:

 pid_t pid = fork(); if (0 == pid) { /* Child process. */ } else { /* Parent process, wait for child to complete. */ int status; waitpid(pid, &status, 0); } 
+7
source

Yes, but I need the parent and child to work asynchronously.

Actually, I found my mistake. So, if someone has a similar problem, with a signal handler function, for example:

 void catch_child(int sig_num) { /* when we get here, we know there a zombie child waiting */ int child_status; wait(&child_status); } 

and signal (SIGCHLD, catch_child)

everything works in main () function.

PP Here: - a very good explanation.

+2
source

All Articles