Questions tagged [waitpid]

The `waitpid()` function is a POSIX function designated for waiting for status changes and for obtaining the status information about the child process whose status has changed.

The waitpid() function is a POSIX function designated for waiting for status changes and for obtaining the status information about the child process whose status has changed.

Being used together with the fork() function, the waitpid()function allows to take control over the child process status changes in a variety of ways. The function behavior is very flexible and depends on parameters passed to the function arguments. However, exists another way to deal with the child process status changes ignoring them. This can be achieved by ignoring the SIGCHLD signal, delivered by the kernel to the parent process when a child process terminates or stops.

299 questions
2
votes
1 answer

ptrace(PTRACE_SINGLESTEP) + waitpid = SIGCHLD

I'm ptracing a multithreaded application and 9 out of 10 times, the breakpointhandling works just fine, but sometimes i get a SIGCHLD event instead of SIGTRAP. This is the sequence: application is running, main thread hits INT3 debugger's waitpid…
rydberg
  • 63
  • 6
2
votes
1 answer

How to wait for threads to finish their work, where threads created by clone in c?

I try to wait the main function, till the threads finish their work. But the main function finish its work and exit. I think because of that the threads has not the correct pointers/values in the variables.(tally and steps) Does someone know how to…
Kami
  • 459
  • 1
  • 6
  • 27
2
votes
4 answers

Why would waitpid in Perl return wrong exit code?

I get wrong exit code from waitpid and I can't figure out why. Could someone give me some ideas? Here what I do: I start my child process with open2 then I wait for it to finish with waitpid get exit code using $? It always returns with -1 no…
Paulius Liekis
  • 1,676
  • 3
  • 18
  • 26
2
votes
1 answer

"no child process" error when calling waitpid twice

For some reason, I have to call waitpid twice on the same child process: Calling the waitpid the first time and there are no errors: waitpid(pid, &status, WUNTRACED); The second time: waitpid(pid, &status, WNOHANG|WUNTRACED); An error occurred:…
Shuai Zhang
  • 2,011
  • 3
  • 22
  • 23
2
votes
2 answers

Why does this code fail? child not waiting

Ok so I have been trying to learn to master child processes and properly waiting for them to finish. I have read a lot of Stack Overflow Q/A and I still can't seem to get this to work as I want it to. I have been reading/searching through the book…
dusz
  • 913
  • 1
  • 9
  • 15
2
votes
1 answer

Using wait() instead of waitpid() within a while loop

I know that one of the differences between wait() and waitpid() is that waitpid having a WNOHANG option which tells the waitpid not to block if there are running children that have not yet terminated. Such as: while ( (pid = waitpid(-1, &stat,…
Nmzzz
  • 2,462
  • 3
  • 19
  • 18
2
votes
2 answers

Why to fork() and then wait() in parent?

I know fork(), wait(), waitpid(), zombie processes... I understood them by reading W. Richard Stevens which is a very good book. If we don't call wait() in parent the child becomes a zombie after termination... which is bad! If we call wait() in…
Sam
  • 1,842
  • 3
  • 19
  • 33
2
votes
2 answers

Fork output with waitpid

int main() { if(Fork() == 0) { printf("a"); } else { printf("b"); waitpid(-1, NULL, 0); } printf("c"); exit(0); } The above code asks what are the possible outputs? I find that, acbc, abcc, bacc…
mausmust
  • 105
  • 1
  • 1
  • 7
1
vote
1 answer

Waitpid in c++ creating problems

I am using waitpid as given waitpid(childPID, &status, WNOHANG); This is used in a program inside an infinite loop that forks when needed and the parent waits for the child process to return. But recently I have come across a problem where in the…
Prasanth Madhavan
  • 12,657
  • 15
  • 62
  • 94
1
vote
2 answers

Spawned child exits with state = 127

I use posix_spawnp to execute different processes and I check the status (with waitpid) to make sure the child was created properly int iRet = posix_spawnp(&iPID, zPath, NULL, NULL, argv, environ); if (iRet != 0) { return…
Gayan
  • 1,697
  • 7
  • 26
  • 35
1
vote
2 answers

waitpid() fail sometime when SIGINT is sent by a ctrl+c

waitpid() returns -1 from time to time when the process in question has received a SIGINT via a ^C. But I can't reproduce this problem if I send a SIGINT signal via pkill for example. The value of errno is set to EINTR. I have a parent process that…
lseiller
  • 25
  • 4
1
vote
0 answers

Getting result of exec*() from child process without waiting in any case (not using pipes and vfork())

I am working on custom wrappers for Unix-specific system calls now. And the last problem I met is about how to create a complete function for creating new processes with another image. And I want this function to return TRUE or FALSE. The last piece…
1
vote
1 answer

How can waitpid() reap more than one child?

In this example from the CSAPP book chap.8: \#include "csapp.h" /* WARNING: This code is buggy! \*/ void handler1(int sig) { int olderrno = errno; if ((waitpid(-1, NULL, 0)) < 0) sio_error("waitpid error"); Sio_puts("Handler…
sociala
  • 11
  • 3
1
vote
1 answer

How can I wait for both a file-descriptor and child state change simultanously?

In Linux, one can wait on any FD using select, poll or epoll. It is also possible to wait for child-processes to change state using wait, waitpid or waitid. However, I can't figure a way to combine these operations, i.e., to block the calling…
shapaz
  • 43
  • 4
1
vote
0 answers

ptrace: attaching to a stopped process

I want to ptrace-attach to a process that has been paused by sending SIGSTOP to it. I then want to continue running the process under ptrace. However, it seems that when attaching to a process that is already in a stopped state when attaching - then…
bernd feinman
  • 324
  • 2
  • 11