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

Pipe and Process management

I am working on a tiny shell(tsh) implemented in C(it's an assignment). One part of assignment belongs to PIPING. I have to pipe a command's output to another command. e.g:ls -l | sort When I run the shell, every command that I execute on it, is…
Neo
  • 349
  • 5
  • 18
3
votes
1 answer

Variable modification in a child process

I am working on Bryant and O'Hallaron's Computer Systems, A Programmer's Perspective. Exercise 8.16 asks for the output of a program like (I changed it because they use a header file you can download on their website): #include #include…
teaLeef
  • 1,879
  • 2
  • 16
  • 26
3
votes
1 answer

Monitoring and restarting child process when fails/exits

I've created a rudimentary example of monitoring a child process and restarting it when it fails or exits. What is the preferred/more robust method of doing this? Is it good practice to continuously poll for a change in status? My understanding is…
CatsLoveJazz
  • 829
  • 1
  • 16
  • 35
3
votes
1 answer

Why waitpid return -1 when run in debugger?

I'm using fork to create a process on a Mac platform, and wait for the child process to finish in the parent process. But the waitpid return -1 and errno is 4 (EINTR). The example code, which can reproduce this problem, is as follows: #include…
ZijingWu
  • 3,350
  • 3
  • 25
  • 40
3
votes
2 answers

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…
donkon
  • 909
  • 9
  • 23
3
votes
2 answers

WSTOPSIG(status) == 22 & WTERMSIG(status) == 9; Where do these numbers come from?

I'm looking over an implementation of esh (easy shell) and cannot understand what signals are 22 and 9 in this case. Ideally there is a more descriptive constant, but I cannot find a list.
Geofram
  • 35
  • 1
  • 6
3
votes
1 answer

wait() function in Ubuntu

I am learning Processes and their behavior in Ubuntu, but I am a bit confused in wait(). So my questions are: How the statment while(wait(NULL)>0); is working? What is the purpose of NULL in wait()? I have seen the output in the terminal but the…
Alfred James
  • 1,029
  • 6
  • 17
  • 27
3
votes
5 answers

Waiting for threads of another process using waitpid

I am trying to use waitpid() for waiting for individual threads instead of processes. I know that pthread_join() or std::thread::join() are the typical ways for waiting for a thread. In my case, however, I am developing a monitoring application that…
betabandido
  • 18,946
  • 11
  • 62
  • 76
2
votes
2 answers

Running/pausing child processes in C?

I'm running child processes in C and I want to pause and then run the same child process. Not really sure how to describe my problem in a better way since I'm new at this but here's a shot. So I know that you can run a process after another process…
Derek
  • 11,980
  • 26
  • 103
  • 162
2
votes
2 answers

UNIX processes: fork() and wait()

this is my question on fork() and the respective wait() that will take place: In my main(), I call a function, let's say function() that uses the fork() system call, but I want function() to return without waiting for the children to terminate, and…
fratzola
  • 21
  • 3
2
votes
1 answer

Why can waitpid(2) specify a non-child process?

I checked the man page for waitpid, but the ERROR section indicates: ECHILD (for waitpid() or waitid()) The process specified by pid (waitpid()) or idtype and id (waitid()) does not exist or is not a child of the calling process. (This can…
LandP
  • 173
  • 6
2
votes
2 answers

In the Linux kernel, why does the SIGCHLD signal not interrupt the wait() system call?

Consider a scenario like this: The parent process calls wait() to wait for the child process to exit, and the signal handler is registered for SIGCHLD. When the parent process blocks at wait(), the child process ends, at which point the parent…
meowrainy
  • 21
  • 2
2
votes
0 answers

Guarantees for waitpid() after epoll() from pidfd

I am writing a process manager that monitors its` child processes and restarts them if necessary. Currently, I have pidfd associated with every running process and epoll waiting for all of these pidfds. When one process terminates, epoll_wait()…
DebNatkh
  • 31
  • 3
2
votes
1 answer

Why zombie process disappears from htop if i don't call waitpid()?

#include #include #include int main() { int pid = fork(); if (pid == 0) { printf("I am Child\n"); exit(0); } printf("I am Parent\n"); …
2
votes
1 answer

waitpid() function returns ERROR (-1), why?

I'm writing a Linux shell-like program in C. Among others, I'm implementing two built-in commands: jobs, history. In jobs, I print the list of currently working commands (in the background). In history I print the list of all commands history until…
spano
  • 370
  • 1
  • 14