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

Does waitpid alone enough to kill a process?

Does this line of code kill and reap a child process without a kill operation? waitpid(pid,&cs,0); Or, must it be in this format to kill and reap a process? kill(pid,SIGTERM); waitpid(pid,&cs,0);
Yazgan
  • 151
  • 11
1
vote
1 answer

How to wait for a child process and get its return value

I am trying to fork my C application, running on an embedded linux environment, and get its return value for failure/success analysis. I looked at similar questions (e.g. this, this, this, this and some other Q/A..) but still can't get it to…
sagivd
  • 120
  • 2
  • 11
1
vote
1 answer

waitpid and signal handler, C

I tried to find an answer to my question at this post: Signal handler and waitpid coexisting but for me isn't very clear at the moment. I try to explain my problems: I'm trying to write a C program that concerns IPC between a parent process and its…
gaet
  • 11
  • 1
1
vote
2 answers

Reading from a pipe to my child process

Hopefully a simple question. I'm trying to learn, simultaneously, fork(), pipe(), and waitpid() and running into some problems. if (pipe(myout)<0 || pipe(myin)<0 || pipe(myerr)<0) { perror("Couldn't make pipes"); return; } int childpid=fork(); if…
Robert
  • 6,412
  • 3
  • 24
  • 26
1
vote
1 answer

Make child process not zombie until waitpid

Is there Linux or POSIX method for instructing a process to not turn into a zombie when it finishes and the parent does not call waitpid()? I know that the parent process we could use SA_NOCLDSTOP for the SIGCHLD handler but that is not an option…
Jeroen Ooms
  • 31,998
  • 35
  • 134
  • 207
1
vote
0 answers

Weird waitpid behaviour

Assume I have the following code. int main(int argc, char* argv[]) { char* program[3] = {"/bin/ls", NULL, NULL}; pid_t pid = fork(); if (pid == 0) { char* envp[1] = {NULL}; execve(program[0], program, envp); } int status; …
insumity
  • 5,311
  • 8
  • 36
  • 64
1
vote
1 answer

Checking if wait() failed

In order to know if wait() has worked, will it be correct to check it like the following? In theory, if wait() does not fail, should return to the parent process the ended child pid, otherwise parent pid will be 1, right? switch (process =…
user7009420
1
vote
0 answers

wait() returns 0 and errno = "Interrupted system call"

I'm doing a school assignment that basically involves creating a couple of child processes which approximate pi and write their results to a text file with the same name as the child process id. The parent process then waits for all the children and…
Magnus
  • 17,157
  • 19
  • 104
  • 189
1
vote
2 answers

C: fork() inform parent when child process disconnects

I am doing a simple server/client program in C which listens on a network interface and accepts clients. Each client is handled in a forked process. The goal I have is to let the parent process know, once a client has disconnected from the child…
lockdoc
  • 1,539
  • 1
  • 18
  • 31
1
vote
0 answers

Negative exit value with WEXITSTATUS

I have a child process that is designed to exit under certain conditions, I have used exit(-2). But after calling WEXITSTATUS the value is around 256. If I use exit(2) the proper value is returned by WEXITSTATUS. Any reason why using a negative…
1
vote
1 answer

Semaphores with three processes

A memory location is shared by three processes. Each process independently tries to increase the content of the shared memory location from 1 to a certain value by increments of one. Process 1 has target of 100000, Process 2’s target is 200000 and…
KoolaidLips
  • 247
  • 1
  • 8
  • 20
1
vote
1 answer

When to use waitpid() to find status of background process

I'm trying to write basic shell program that will manage job control with background processes. I understand to send a process to the background you call fork(), but don't wait for it in the parent. However, I also know you need to call waitpid()…
purelyp93
  • 65
  • 1
  • 9
1
vote
1 answer

How does the Linux shell get the return code value for $? variable?

Does the Linux shell do a fork/exec and then waitpid() to get the return code to populate the $? variable, each time it executes something?
Scooter
  • 6,802
  • 8
  • 41
  • 64
1
vote
1 answer

How to wait for multiple instance of one program to complete in linux?

How can I wait for multiple instance of same program to finish ? Below is my scenario any suggestion or pointers ? I need to restart a running C process. After googling for long time, I figured out restarting can only done by fork and exec(I need…
Hipster1206
  • 411
  • 6
  • 13
1
vote
1 answer

waitpid() return value 0 along with errno EINTR

I am trying to write a program in which I am forking a child from a parent, and handling SIGCHLD signals using a handler, in which I use waitpid(). When I execute it, however, I am sometimes getting a return value of 0 from waitpid, along with errno…
Parag Goel
  • 123
  • 2
  • 14