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
3
votes
2 answers

Why do we need a wait() system call?

Hello I am new to learning about system calls. I am currently learning about fork() and wait() system calls. I know that fork() creates a new child process. What confuses me is the wait() call. This is what I understand so far: (1) When a process…
JANVI SHARMA
  • 115
  • 1
  • 11
3
votes
1 answer

Differentiate processes states using waitpid and WNOHANG

While building a shell program I'm facing an issue of recognizing processes states. The description of the issue I'm facing with is that I have a list of child processes and I'm trying to figure out their state using waitpid and WNOHANG. I wish to…
3
votes
1 answer

Waitpid waiting on defunct child process

In case of crash we dump the stack to get more information about the crash using below function: static void dumpStack()     {         char buf[64];         pid_t pid = getpid();         sprintf( buf, "%d", pid );         pid_t fork_result =…
Euler
  • 652
  • 3
  • 11
  • 24
3
votes
1 answer

How can I wait for a Rust `Child` process whose stdout has been piped to another?

I want to implement yes | head -n 1 in Rust, properly connecting pipes and checking exit statuses: i.e., I want to be able to determine that yes exits due to SIGPIPE and that head completes normally. The pipe functionality is easy (Rust…
wchargin
  • 15,589
  • 12
  • 71
  • 110
3
votes
1 answer

Can a process wait for a PID that is not one of the children?

I was wondering if we can use the system call waitpid() to wait a pid of a grandchildren
Tsadoq
  • 224
  • 3
  • 17
3
votes
1 answer

waitpid - In which cases both WIFEXITED and WIFSIGNALED will be false?

I'm running a Java program as a daemon on Linux using Apache commons-daemon's jsvc. The daemon "randomly" crashes with only message: jsvc.exec error: Service did not exit cleanly This is the relevant part of the code in jsvc (in jsvc-unix.c line…
nicoulaj
  • 3,463
  • 4
  • 27
  • 32
3
votes
0 answers

Is status value from os.waitpid unreliable when os.WNOHANG is used under FreeBSD?

The os.waitpid docs https://docs.python.org/2.7/library/os.html#os.WNOHANG say that if the child process is not yet exited, then the return value will be (0,0) however on FreeBSD (FreeBSD 10.3-RELEASE-p7) sometimes (0,-512) or (0,-2048) is returned.…
clucas
  • 166
  • 2
  • 9
3
votes
2 answers

Why won't AnyEvent::child callbacks ever run if interval timer events are always ready?

Update this issue can be resolved using the fixes present in https://github.com/zbentley/AnyEvent-Impl-Perl-Improved/tree/io-starvation Context: I am integrating AnyEvent with some otherwise-synchronous code. The synchronous code needs to install…
Zac B
  • 3,796
  • 3
  • 35
  • 52
3
votes
1 answer

Creating a process tree

The following program should create processes tree of depth K with N children on each node. #include #include #include #include #include void spawnNodes(int curLevel, int levelLimit, int…
cristid9
  • 1,070
  • 1
  • 17
  • 37
3
votes
1 answer

getrusage not working as I would expect

I am trying to measure the amount of memory used by a child process via the getrusage system call with the following code #include using std::cout; using std::endl; #include #include #include #include…
Curious
  • 20,870
  • 8
  • 61
  • 146
3
votes
1 answer

python multiprocessing - select-like on running processes to see which have one have finished

I want to run 15 commands but only run 3 at a time testme.py import multiprocessing import time import random import subprocess def popen_wrapper(i): p = subprocess.Popen( ['echo', 'hi'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) …
ealeon
  • 12,074
  • 24
  • 92
  • 173
3
votes
1 answer

wait() does not wait for every child

I have a loop that creates 'n' child processes. The processes go into a separate program and sleep for 'x' seconds then return with exit status 'x'. The issue is when I try to wait for each individual process. It seems that my wait() call wait for…
Andrew Ricci
  • 475
  • 5
  • 21
3
votes
1 answer

In Linux, how can I wait until a process I didn't start finishes?

I have a monitoring program that I'd like to check on various processes in the system, and know when they terminate. I'd also like to know their exit code, in case they crash. However, my program is not a parent of the processes to be…
Myria
  • 3,372
  • 1
  • 24
  • 42
3
votes
1 answer

waitpid for child process not succeeding

I am starting a process using execv and letting it write to a file. I start a thread simultaneously that monitors the file so that it's size does not exceed a certain limit using stat.st_size. Now, when the limit is hit, I waitpid for the child…
user1295872
  • 461
  • 1
  • 6
  • 16
3
votes
1 answer

When and why should you use WNOHANG with waitpid()?

I'm currently in a systems programming class and we went over the wait system call functions today. I was reading over the section on waitpid() system call and in the options section it lists one called WNOHANG. pid_t waitpid*(pid_t pid, int…
user3305321
  • 31
  • 1
  • 1
  • 2