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

What happens when two processes wait for the same child?

From what I've read the default behavior for wait/waitpid is to wait for a state change in a process. What I can't find is the expected behavior of two processes waitpid using the same pid_t argument. Do both return and continue execution, or is it…
JBolton
  • 127
  • 2
  • 11
2
votes
1 answer

C in Unix: fork, waitpid and pipes

My question is about how to control the process execution with regards to pipes, and specifically implementation of wait / waitpid function. When I create a pipe for the following command ls | head -3, I do the following: I create the pipe, fork…
Pavoo
  • 75
  • 2
  • 6
2
votes
2 answers

How to wait for running process to complete in perl when running process is not child process?

I am going through a Perl script which is using waitpid($pid, 0) to wait for current process to complete. But print statement written right after this waitpid is printing it before the process gets complete. I want to know why waitpid is not…
user3395103
  • 131
  • 1
  • 3
  • 13
2
votes
2 answers

Prevent SIGALRM from interrupting waitpid()

I'm trying to make my process waitpid() for a child process, but also print something every interval amount of time. My current plan is to schedule an itimer, waitpid(), handle the SIGALRM printing, and stopping the timer when the waitpid()…
Matt Goodrich
  • 4,875
  • 5
  • 25
  • 38
2
votes
1 answer

Waitpid blocks forever

I have a little confusion with waitpid function: int main(int argc, char** argv) { if (pid_t pid = fork()) { setpgid(pid, pid); waitpid(pid, NULL, 0); } else { setpgid(0, 0); char *args[] = {"man", "2",…
Alexandr
  • 105
  • 7
2
votes
1 answer

Will exit the program automatically close the pipe?

Say I create a pipe between child and parent process and the child process ends normally, will child process's pipes been closed automatically? Also, If the child process also has a child process and the child process ends with a segmentation fault,…
user5574376
  • 371
  • 1
  • 5
  • 12
2
votes
0 answers

LibUV process and waitpid()

I am creating a process using LibUV on Visual Studio 15. I want to do something like this : createsProcess() { pid_t pid; pid = myspawn(cmd, argv, my_fds, 1); while(waitpid(&pid, child_status,0 == -1 && errno = EINTR)); } } The code…
K92
  • 21
  • 5
2
votes
0 answers

WIFEXITED false although child exited normally, without segfault

I am trying to implement strace -f. Please look at the main loop of my program: static void trace_syscalls(pid_t pid) { int status; wait(&status); unsigned int options = PTRACE_O_TRACEFORK | PTRACE_O_TRACECLONE | PTRACE_O_TRACEVFORK |…
kst
  • 21
  • 3
2
votes
0 answers

waitpid on ptrace'd non-child thread

I have used ptrace to force a thread within another process to call sys_clone and create a new thread with pid pid, with the clone flags CLONE_FILES, CLONE_FS, CLONE_IO, CLONE_PTRACE, CLONE_SIGHAND, CLONE_THREAD and CLONE_VM. As I understand from…
2
votes
1 answer

Return value of waitpid() in linux

When the waitpid() function is implemented in the following way,what does it return when the child is stopped due to SIGTSTP signal? and why? waitpid(pid,&status,WUNTRACED); where pid is process id of any process and status is of type int. Does it…
Prerak
  • 57
  • 1
  • 7
2
votes
1 answer

What would WIFEXITED(status) be when a process just ran the command 'true'?

If I run the following code segment pid_t p; int status = 0; p = fork(); if (p < 0) report_error(); if (p == 0) // child { execlp("true", "true", 0); _exit(127); // we should not get here } else { waitpid(p, &status, 0); …
gautam
  • 302
  • 5
  • 17
2
votes
1 answer

C - Waiting for one child to terminate

I am creating multiple child processes in a loop. Each child will do it's thing and anyone of them can end first. (Not sure if relevant but: Each child also has a grandchild) How do I wait for any child process to terminate and stop the others when…
Guybrush
  • 201
  • 1
  • 4
2
votes
3 answers

Waiting for child process to terminate, or not - C

I'm trying to do an assignment for one of my classes and no professors/fellow classmates are getting back to me. So before you answer, please don't give me any exact answers! Only explanations! What I have to do is write a c program (timeout.c) that…
FateNuller
  • 878
  • 2
  • 12
  • 27
2
votes
2 answers

WEXITSTATUS(childStatus) returns 0 but waitpid returns -1

As far as I know if waitpid returns -1 then it is error condition. How it possible to get success (EXIT_SUCCUSS) from child process in WEXITSTATUS(childStatus)? What is the difference between childStatus in waitpid & return value from…
kapilddit
  • 1,729
  • 4
  • 26
  • 51
2
votes
1 answer

Segfault on cat/waitpid (Execve in C)

My friends and I are trying to code a shell. My problem is that running 'cat' command and then exit STDIN with ^C makes my program segfault on waitpid and so quit my program... (What I don't want of course !) Every command is working perfectly and I…