What is the problem with this code? How to solve it? (fork)

Posted by sb2367 on Stack Overflow See other posts from Stack Overflow or by sb2367
Published on 2010-04-09T21:42:10Z Indexed on 2010/04/09 21:53 UTC
Read the original article Hit count: 156

Filed under:
|
|
|

What is the problem with this code? How to solve it? Parent processes goto in if or child process?

first code produce zombie process or second code or both or non ?

#include <signal.h>
#include <sys/wait.h>
main() {
  for (;;) {
    if (!fork()) {
      exit(0);
    }
    sleep(1);
  }
}

what about this code :

#include <signal.h>
#include <sys/wait.h>
main() {
  for (;;) {
    if (fork()) {
      exit(0);
    }
    sleep(1);
  }
}

© Stack Overflow or respective owner

Related posts about c

    Related posts about fork