How can I get status processes in a C project?

113 Views Asked by At

for my C project I need to know in which state (running, waiting, terminated, ...) the various processes are. The processes are created by myself using many fork(). Does anyone have any idea how to do that?

Example: I have a process with PPID = x I do 3 fork() -> I get three new processes with PID = x+1, PID = x+2, and PID = x+3 (more or less). I need to know if the processes with PID = x+1, PID = x+2, and PID = x+3 are running or waiting or terminated.

1

There are 1 best solutions below

1
Anthony Schanen On

if you do 3 fork()'s you have more than 3 new processes. You have 2^n processes. n being the number of times you call fork()

for example

#include <stdio.h> 
#include <sys/types.h> 
int main() 
{ 
    fork(); 
    fork(); 
    fork(); 
    printf("hello\n"); 
    return 0; 
}

prints this

hello
hello
hello
hello
hello
hello
hello
hello

also I do believe your question has been answered here