How to count the number of process created by system call fork()
without using file writer
. This is the code I'm trying but it doesn't work! It would be helpful to get some feedback. Thanks in advance.
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
int pid_count = 0;
int main(){
pid_t pid = fork();
pid_t pid2 = fork();
if(pid == 0 || pid2 == 0){
pid_count++;
}
if(pid > 0 || pid2 > 0){
wait(NULL);
printf("%d\n", pid_count);
}
return 0;
}
Output:
1 1 0