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

How to check any thread is working currently

I know there is one for multi processes waitpid(-1,WNOHANG,NULL) that is non-blocking function call to check if there is any child process currently working on But is there any similar lib function to check for multithread? All i want to do is…
REALFREE
  • 4,378
  • 7
  • 40
  • 73
0
votes
1 answer

I have a problem with the WIFSIGNALED()/WTERMSIG() macros, after using waitpid()

In this code C i launch a program from the command line and when it is closed from a signal different from SIGTERM (signal for normal end) my code should relaunch the initial program passed from the command line. But it is not so, in fact my code…
Andrea
  • 23
  • 1
  • 4
0
votes
2 answers

Child processes with fork

I am trying to make a simple C program that will call the fork method three times and display identifiers of child processes (UID, GID, PID, PPID, PGID). And I am struggling with proper understanding what is really happening. There is my code in…
lolek
  • 59
  • 3
  • 12
0
votes
1 answer

Not able to get waitpid() to return correct WEXITSTATUS for error condition

I have a command and some input that when run on the command line will return an error, with an associated error code of 1: $ foo bar [some useful error message...] $ echo $? 1 I am trying to catch this error code with waitpid(): ... char *proc_cmd…
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
0
votes
4 answers

waitpid() not waiting for child

I wrote a really basic shell and for some reason, when I use fork() and then waitpid() the parent process won't wait for the child. #include #include #include #include #include #include…
Joseph
  • 11
  • 1
  • 3
0
votes
2 answers

Why is waitpid(-1, &status, 0) not suspending the process without any childs at all?

I don't understand the waitpid() function very well. The manual says: The wait() system call suspends execution of the calling process until one of its children terminates. The call wait(&status) is equivalent to: waitpid(-1, &status,…
user3542317
  • 193
  • 2
  • 12
0
votes
1 answer

How to wait for process running in gnome-terminal > 3.8

GNOME developers removed option disable-factory from gnome-terminal in about version 3.8. While in wheezy there is older version, in jessie there is 3.14. When that option was used gnome-terminal (<3.8) left waiting until the stuff running it it…
Michał Fita
  • 1,183
  • 1
  • 7
  • 24
0
votes
1 answer

waitpid() returns -1 if fopen() exists

i was wondering why waitpid() returns -1 while fopen() exists. FILE *fp = fopen ("abc.txt", "r"); fclose(fp); pid_t pid = fork (); if (pid == 0) { /* child process */ printf ("child %d\n", getpid()); } else { /* parent process…
0
votes
1 answer

execve() returning error on first loop only

I've been puzzling over this for a while, and now I could use some help. I'm trying to create a loop which will fork off a child process and call "echo hello" through execve(). #include #include #include int…
Hal
  • 37
  • 4
0
votes
0 answers

Using waitpid() to get only status information

For my school assignment, my professor wants me to store the state of background processes that i've made with my program and stored in a process table with each process entry being either "in progress" or "completed". To check whether a process has…
shawn a
  • 799
  • 3
  • 13
  • 21
0
votes
1 answer

waitpid not receiving exit status when child executes execvp

I am trying to create a shell like program . Wrote a sample snippet program to see the execution of ls | wc. In the sample program the main process creates a childprocess for the execution of each command(using execvp) and passes the output using…
Kai
  • 953
  • 6
  • 16
  • 37
0
votes
1 answer

waitpid and open3 in Perl

If output of the program that is called by open3 is too large (more than 65536) waitpid will run forever. use IPC::Open3; use POSIX ":sys_wait_h"; …
chessman
  • 47
  • 2
  • 6
0
votes
1 answer

How to make sure my child executes first and then parent?

Here below i have a simple code snippet of application which takes request from several clients and invokes mathematical operations through exec and waits for result from invoked processes to return those results to the respective clients through…
kakeh
  • 403
  • 3
  • 17
0
votes
1 answer

C - Under what conditions will a call to waitpid() return -1, signalling an error?

I'm writing a SIGCHLD handler and I'm wondering under what conditions would a call to waitpid() return -1? More specifically, if I create a loop in which I call waitpid(...) and want it to run until all terminated child processes have been reaped,…
fvgs
  • 21,412
  • 9
  • 33
  • 48
0
votes
1 answer

Pipelines and waitpid

I've got a problem with my pipeline. I looked through the topics, but did not find anything for my problem. My pipeline works fine, but I want to know when my children terminate. So I want to use waitpid to check my children. But that does not…
user1550036
  • 211
  • 1
  • 3
  • 9