I'm creating a sequence of processes through the command fork
, but when I was listing the processes generated by the code, I came across that there was a larger amount than I had created. Why this?
By 10
forks
1024 processes were generated.
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(int argc, const char **argv){
int fork_id[10];
int x;
for(x=0; x<10; x++){
fork_id[x] = fork();
if(!fork_id){
execl("/usr/bin/sleep", "5", NULL);
}
}
sleep(10);
return 0;
}
To check the number of processes I used ps
:
ps aux | grep test_fork | grep -v grep | wc -l