I was going through the documentation of the system call wait4()
and in its man page it is written
These functions are obsolete; use
waitpid(2)
orwaitid(2)
in new programs.
So, I went through the documentation of waitpid()
and I saw that there is a difference between the two.
waitpid()
does the same things as wait4()
, but wait4()
, according to the man page,
additionally return resource usage information about the child in the structure pointed to by
rusage
.
The two system calls are defined as follows
pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage);
pid_t waitpid(pid_t pid, int *status, int options);
Now, I also read that there is a another system call that does that extra job of getting the rusage
of the child and that is getrusage()
.
So, I can understand that what wait4()
could do, one can do the same thing by using a combination of waitpid()
and getrusage()
.
But, what I am not understanding is, there is always a strong reason for making a system call obsolete. But in this case it feels that the functionality has been split.
- If I want to use the combination of
waitpid()
andgetrusage()
, I have to check the return values twice, which was not the case forwait4()
. - Additionally one can use
wait4()
to getrusage
of a specific child, butwaitpid()
would givesrusage
of all its children together (if used withRUSAGE_CHILDREN
). That sounds like extra overhead if there are more then few child processes.
Why was wait4()
made obsolete? It seems like it made things harder.
wait4()
without gettingrusage
. One has to make the last parameterNULL
. – Bytewait4()
is using since it's not accessible via the standardrusage()
function. I know that we can find the info in the/proc
file system, but I'd say that's even worse! – Bushman