I get the same most of the time, but if you look carefully, you will occasionally get a process that actually used user time. Grep the output like this: "prog | grep -v 00000$".
Also, note that by not exiting or returning after the printf, you create a "fork bomb". Your process will run endlessly, forking processes on end.
Why the exec takes so little user-time? Because you're making exactly one library function call as a user, which calls the system exec() call, which from at that point belongs to the system time.
First of all, i would like to thanx you for the help.
is there an explanation why wait4 and getrusage(RUSAGE_CHILDREN,..) give me different values!!
for example, wait4=most values are in the range of (0.00000, 0.01000)
and in the other hand, getrusage values varies from 4.17 to 4.20
why this happens?
I already gave you the answer: getrusage(RUSAGE_CHILDREN...) is cumulative.
Cumulative means: it adds all children together. It reports all values (added together) for all of the children waited for.
wait4 waits for ONE child, it does not add resources used for all children together.
wait4 == one child
getrusage(RUSAGE_CHILDREN...) == all children.
Your example gets almost no printable results but zero because your child process does almost nothing: get created and then call exec. For this one operation on a fast machine, it is possible to be a very small amount of time, smaller than the granularity of the timeval struct.
If you do hundreds of these eventually they add up to a value that displays non-zero.
To see results:
Try having execl() call some tiny C program that does something both pointless and hopefully harmless: opens a process-specific filename, writes to the file, closes the file, then removes the file.
see man tmpnam to be able to create a safe filename. Be sure to remove the file.
helo,
i read man pages but still confuse about
wait3() and wait4() stystem call
what is exact diff b/w wait3() and wait4() system call
and what is diff b/w waitpid() and wait3() and wait4()
Regards,
Amit (1 Reply)