Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
waitpid returns pid=0 and WIFEXITED=1 how to get pid?

Steps:

Fork and start process in a different program group
Stop process with SIGTSTP
Restart process with SIGCONT
Process ends

Problem: The SIGCHLD handler has:

waitpid(-1, &status, WNOHANG | WUNTRACED);

upon return pid=0 and WIFEXITED=1 so, the process exited, but I can't get the pid? I need the pid.

From the man page: "if WNOHANG was specified and one or more child(ren) specified by pid exist, but have not yet changed state, then 0 is returned"
But it seems the status has changed to exited.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

The status is meaningless if the pid returned was 0. Think about it. A return of 0 means you have one or more children that have yet to change state. What would the state of a child that has yet to change state be? If there were multiple children, which child is the status code referencing?

This is analogous to checking errno on a successful call. Anything from a previous call can be in errno but it has nothing to do with the most recent successful call because errno is usually not set on success.

over 4 years ago · Santiago Trujillo Report

0

The return value of waitpid is the PID of the child that was waited for.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!