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);
}
}
RETURN VALUE
Upon successful completion, fork() shall return 0 to the child process and shall return the process ID of the child process to the parent process. Both processes shall continue to execute from the fork() function. Otherwise, -1 shall be returned to the parent process, no child process shall be created, and errno shall be set to indicate the error.
=================
What did you mean, not to create processes after one successfully created? Seems like a problem…