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
1
vote
1 answer

Parent and multiple chilrend PID. Fork & waitpid - functions

I'm having problems with fork/waitpid functions. I'm trying to make program what first processes and prints children PIDS and after that Parent PID My code: int main(void) { pid_t pid; int rv = 0; int i = 1; pid_t child_pids[2]; …
Tanhua
  • 39
  • 1
  • 5
1
vote
1 answer

the return value of a child process

I am new to fork and exec, and I tried the following program. Program 1: int main(int argc, char *argv[]){ pid_t pid; int status; pid = fork(); if(pid == 0){ printf("new process"); execv("p1",argv); } …
richard.g
  • 3,585
  • 4
  • 16
  • 26
1
vote
1 answer

cleaning child processes with handler with waitpid pselect fork sigaction

I have a server that receives messages into a socket and for each message received, do a fork exec. This part seems to be working properly. But I need to do this in non-blocking mode, so I've created a handler to clean properly all the terminated…
thorgal99
  • 13
  • 5
1
vote
2 answers

Waiting process to return

Consider: int main() { if (fork() == 0){ printf("a"); } else{ printf("b"); waitpid(-1, NULL, 0); } printf("c"); exit(0); } (from Computer Systems, Bryant -…
teaLeef
  • 1,879
  • 2
  • 16
  • 26
1
vote
0 answers

Can I Get the Pids of Exiting (defunct) Processes Programmatically?

I'm running into a problem where it'd be really nice to know what processes are exiting before calling waitpid() — because I might want to get information from the /proc directory on that process, depending on which it is. I'm curious if there is a…
dbeer
  • 6,963
  • 3
  • 31
  • 47
1
vote
0 answers

Signal to sleeping process

I want to know what happens to a process when it is sleeping a receive a signal, and how to force it to complete the inicial wait in spite of the signal. I think that when a process is sleeping (with sleep() for example), when it receives a signal…
aDoN
  • 1,877
  • 4
  • 39
  • 55
1
vote
1 answer

Don't want to remove terminated child process immediately, need to become zombie

I got below information from SE QUE Explicitly setting the disposition of SIGCHLD to SIG_IGN causes any child process that subsequently terminates to be immediately removed from the system instead of being converted into a zombie. As far I know, to…
kapilddit
  • 1,729
  • 4
  • 26
  • 51
1
vote
1 answer

Which one to choose waitpid/wait/waitid?

I want to use execl in child process after doing fork. execl will execute the script which will take around 120 seconds of time. I tried almost all the combination with waitpid, wait and waitid with different argument (0, WNOHANG, etc.,) but in all…
kapilddit
  • 1,729
  • 4
  • 26
  • 51
1
vote
3 answers

waitpid with execl used in child returns -1 with ECHILD?

When do I need to use waitpid if I am using execl in a child process which may take time to finish? When I use waitpid in the parent, it tells me that the child is running as the return value from waitpid is 0. However, if I call waitpid after some…
kapilddit
  • 1,729
  • 4
  • 26
  • 51
1
vote
2 answers

How to properly count an actual number of forked child processes?

Some time ago I wrote a simple SMTP gate for automatic S/MIME processing and now it comes to testing. As typical for mail servers, main process forks a child for every incoming connection. It is a good practice to limit the number of created child…
TPhaster
  • 43
  • 8
1
vote
2 answers

waitpid not working- efault error

I am trying to make a fork that runs an exec in one file and then waits for it to be finished. If the exec in the child process is terminated by a signal I want to print the signal, if the program takes too long to run I want to print timeout. …
1
vote
1 answer

fork() and waitpid possible outputs

My textbook gives the following main routine: int main() { if(fork() == 0) { printf("a"); } else { printf("b"); waitpid(-1, NULL, 0); } printf("c"); exit(0); } It asks what the possible outputs…
tomKPZ
  • 827
  • 1
  • 10
  • 17
1
vote
1 answer

What systems do not support WNOHANG option for waitpid?

I have a library for managing child processes that relies on passing the POSIX WNOHANG option to waitpid to perform a non-blocking wait on a process. It is said that not all systems support this option, but it has been a while since I have worked on…
mob
  • 117,087
  • 18
  • 149
  • 283
1
vote
1 answer

fork a long-running process and avoid having to call waitpid to clean up the zombie?

I have a long-running process (node.js) which calls fork (as part of a C++ module). This creates the new process as a child of the node.js process. However, there is nothing that will wait/waitpid for this child process, so it remains a zombie after…
Pavel
  • 5,320
  • 8
  • 35
  • 45
1
vote
3 answers

waitpid/wexitstatus returning 0 instead of correct return code

I have the helper function below, used to execute a command and get the return value on posix systems. I used to use popen, but it is impossible to get the return code of an application with popen if it runs and exits before popen/pclose gets a…
Mahmoud Al-Qudsi
  • 28,357
  • 12
  • 85
  • 125