fork-getrusage

Hello everybody!
I wrote the following code:
...
int main()
{
pid_t pid;
for (int i=0;i<100;i++)
{
pid=fork();
if(pid==0)
{execl("md5sum","myprog",NULL);exit(1)}
else if(pid>0)
{ waitpid(pid,&status,0);getrusage(RUSAGE_CHILDREN,&usage);}

The above program creates 100 processes concurrently! I want to fork one process after another(is finished). What I want to do is, get the utime of child process each time. However, i find out that stime of one process is influenced by the utime of previous process!
Output example:
pid utime
8359 0.172010
8360 0.176011
8406 0.176011
8407 0.176011
8408 0.176011
8409 0.184011
8410 0.184011
Why this happens?

Thanx in advance

RUSAGE_CHILDREN means ALL terminated and waited-for children. You will have to have each child process call getrusage with RUSAGE_SELF, write data to a file. Or bettter to a db, so you do not have concurrency problems.

First I would like to thanx you!!!
The only place i can put getrusage in child process is before execl command, because the command after execl are executed only if execl crushes, Am i right?Do i get the expected time by this way?
Thanx one more time!:b::slight_smile:

PLZ help! I cannot put getrusage after execl, because the commands after execl executed only if execl crashes