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
4
votes
4 answers

Why isn't the process I start with Perl's system() a child process?

Perl's system() starts a process, but breaks the parent/child relationship? test.pl: use POSIX; system("./test.sh &"); my $pid = `ps -C test.sh -o pid=`; print "pid: -$pid-\n"; waitpid($pid, 0); test.sh: while true do sleep 1 done When I…
n-alexander
  • 14,663
  • 12
  • 42
  • 43
4
votes
3 answers

Using sleep and wait -n to implement simple timeout in bash, race condition or not?

If I do this in a bash script: sleep 10 & sleep_pid=$! some_command & wait -n cmd_pid=$! if kill -0 $sleep_pid 2> /dev/null; then # all ok kill $sleep_pid else # some_command hung ...code to log diagnostics and then kill -9…
4
votes
2 answers

Developing a correct understanding of waitpid() and getpid()

I am learning about forks, execl and parent and child processes in my systems programming class. One thing that is confusing me is waitpid() and getpid(). Could someone confirm or correct my understanding of these two functions? getpid() will return…
Chris T
  • 453
  • 1
  • 6
  • 17
4
votes
3 answers

Waitpid and fork/exec's non-blocking advantage over a syscall?

I always hear that you should never use system() and instead fork/exec because system() blocks the parent process. If so, am I doing something wrong by calling waitpid(), which also blocks the parent process when I do a fork/exec? Is there a way…
lolololol ol
  • 848
  • 1
  • 8
  • 18
4
votes
2 answers

Wait for a process to end that is created by a process called

I'm writing a program in python which calls another program via the subprocess.Popen command. The program being called launches a GUI that the user interacts with, but before that it goes through some services to authenticate the user. With that…
coder4lyf
  • 927
  • 1
  • 17
  • 36
4
votes
1 answer

About wait() and waitpid()

So I wrote this code on C. I created a father, that has two child processes, and one becomes zombie. After one second it exits, and the father, that was waiting for him, finishes. The other child process remains orphan, and then finishes. My…
Mr. Kevin
  • 41
  • 1
  • 1
  • 2
4
votes
0 answers

Behavior of waitpid() in multiple threads?

C++ under Linux (CentOS 6.3), using pthreads. gcc 4.7. I am now maintaining a program where the primary thread does a blocking call to waitpid(-1,...) to reap any and all possible children. In a thread spawned earlier from the main thread, I have…
Michael Kohne
  • 11,888
  • 3
  • 47
  • 79
4
votes
1 answer

why the wait() function takes more argument?

i tried with the waitpid() function, it takes three argument, while i implement a below code , i had a some mistakes, instead of waitpid() function i use the wait() function with the three argument. it work properly i don't how its working. Any one…
Bhuvanesh
  • 1,269
  • 1
  • 15
  • 25
4
votes
1 answer

Cannot compile with waitid() and P_PID

I am new to Linux. I am trying to use waitid() to wait for a child process. When I try to compile a file including the following lines using gcc: id_t cpid = fork(); siginfo_t status; waitid(P_PID, cpid, &status, WEXITED); The following error was…
user3545752
  • 351
  • 1
  • 7
  • 15
4
votes
1 answer

waitpid - WIFEXITED returning 0 although child exited normally

I have been writing a program that spawns a child process, and calls waitpid to wait for the termination of the child process. The code is below: // fork & exec the child pid_t pid = fork(); if (pid == -1) // here is error handling code…
Andreas Grapentin
  • 5,499
  • 4
  • 39
  • 57
4
votes
2 answers

What does signal(SIGCHLD, SIG_DFL); mean?

I am not handling SIGCHLD in my code. Still my process is removed immediately after termination. I want it to become zombie process. If I set SIGCHLD to SIG_DFL then, will it work? How do I set SIGCHLD to SIG_DFL? I want process to become zombie, so…
kapilddit
  • 1,729
  • 4
  • 26
  • 51
4
votes
1 answer

Prints before execl is not visible in output

#include #include #include #include #include int main(void) { pid_t Checksum_pid = fork(); if (Checksum_pid < 0) printf("Fork Failed\n"); else if (Checksum_pid == 0) { …
kapilddit
  • 1,729
  • 4
  • 26
  • 51
3
votes
2 answers

Why is the child process a zombie after kill() it

I have a multi-processes program. To briefly illustrate the problem, the child process will be only blocked and the main process judge whether the child process still exists, if exists the parent process kill the child process. My codes are as…
Yongqi Z
  • 605
  • 8
  • 20
3
votes
0 answers

Why does the command "leaks -atExit" hang forever (C program with child process and waitpid)?

I am trying to check memory leaks on a C program containing child processes using the "leaks -atExit -- ./PROGRAM_NAME" command. Note that the program returns normally when executed on its own. The leaks command fails to return when the program…
BlueJohn
  • 31
  • 2
3
votes
0 answers

What is the relationship between ptrace and waitpid?

I am practicing using ptrace but I don’t know much about the relationship between it and waitpid. This is my test program: int main(int argc, char *argv[]) { pid_t pid = 22092; if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) == -1) { …
mark25789
  • 43
  • 3
1 2
3
19 20