0

Let suppose that process-A calls fork

    pid = fork();
    ...
    waitpid( pid, ...);

Is it possible, that between these calls (fork and waitpid) proccess-B, which is created by fork(), may to finish? Then some new process-C starts and gets a pid is equal to an old pid of process-B. And after that waitpid will waits the end of process-C, not B.

The exec-family calls don't return a value and a control if they are successful. The exec starts new process instead current process but keeps a process pid. Is it an any guaranteed way to do fork/vfork + exec + waitpid as a truly "atomic" operation and to get result of a process which is created by exec?

Does bash/shell run, wait commands and return their results in an "atomic" way?

Павел
  • 113
  • 7
  • 2
    The pid of an exited process won't be reused until its parent waits on it and collects the exit information. It lingers as a *zombie* process till then. – Shawn Feb 27 '21 at 14:43
  • 1
    https://stackoverflow.com/questions/16078985/why-zombie-processes-exist might help understand the process. – Shawn Feb 27 '21 at 14:50
  • As I see now, child process will be in "zombie"-status before waitpid() occurs. Thanks! – Павел Feb 27 '21 at 15:17

0 Answers0