Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

654
Visualizações
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.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

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

over 4 years ago · Santiago Trujillo Relatório

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

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda