• Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Precios
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

228
Vistas
why did wait4() get replaced by waitpid()

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) or waitid(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() and getrusage(), I have to check the return values twice, which was not the case for wait4().
  • Additionally one can use wait4() to get rusage of a specific child, but waitpid() would gives rusage of all its children together (if used with RUSAGE_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.

11 months ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

It is a matter of standardization and history. wait4 is a 4.3BSD system call, but POSIX.1 retained waitpid.

11 months ago · Santiago Trujillo Denunciar

0

Taken from http://pubs.opengroup.org/onlinepubs/009695399/functions/wait.html:

The waitpid() function shall be equivalent to wait() if the pid argument is 
(pid_t)-1 and the options argument is 0. Otherwise, its behavior shall be 
modified by the values of the pid and options arguments

so the waitpid() function is provided for three reasons:

To support job control

To permit a non-blocking version of the wait() function

To permit a library routine, such as system() or pclose(), to wait for its 
children without interfering with other terminated children for which the 
process has not waited

And it also include all previous abilities of wait() as explained

11 months ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.