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

where to place wait_pid function to prevent zoombie processes in Linux?

I'm following OpenSSL multi-threaded server example but this example creates zoombie processes. I researched and found that I should do a waitpid() for each forked process. But I'm not able to figure out where to place waitpid(pid, NULL, 0); I…
user837208
  • 2,487
  • 7
  • 37
  • 54
1
vote
0 answers

Reaping children subprocesses in Rust, how to lookup child by PID?

I have a program that uses std::process::Command::spawn, and it produces zombies. I know very well that the parent process must read out children exit codes, otherwise zombies happen. This is also warned about in Rustdocs for std::process, and…
ulidtko
  • 14,740
  • 10
  • 56
  • 88
1
vote
0 answers

How to remove zombie process from my own C UNIX shell

I am writing my own UNIX-shell in C, If write & at the end of the command then the parent wont stop for the child to end and child will be backgrounded. To remove the zombie child process I am using waitpid(-1,&status,WNOHANG) but it returns 0 and…
Rocket
  • 123
  • 8
1
vote
3 answers

Having trouble running 2 child processes

In this program, mulproc.c , I am trying to run the executables from two programs I made (one counts the amount of alphabetic characters in a file and the other one counts five specific special characters). I am trying to make a parent process…
PluffTed
  • 53
  • 5
1
vote
3 answers

How to cancel waitpid if child has no status change?

Disclaimer: Absolute newbie in C, i was mostly using Java before. In many C beginner tutorials, waitpid is used in process management examples to wait for its child processes to finish (or have a status change using options like WUNTRACED).…
ptstone
  • 478
  • 7
  • 17
1
vote
1 answer

How to detect the child's exit when waiting in select() for the anonymous pipe to become readable?

My python program creates a pipe, forks, and then spawns another program from the child. The parent then sits and waits for the reader-side of the pipe to become readable. reader, writer = os.pipe() fcntl.fcntl(reader, fcntl.F_SETFL,…
Mikhail T.
  • 3,043
  • 3
  • 29
  • 46
1
vote
2 answers

How to make parent process wait for child processes to finish?

I have an assignment which gives me this code to transform into a code that makes the parent process wait for all children processes to finish. PS: the first code has 4 processes and needs to use waitpid to solve this. #include #include…
JackRS
  • 11
  • 1
  • 2
1
vote
1 answer

How am I supposed to use *status in waitpid(pid_t pid, int *status, int options)?

I don't understand what *status is supposed to do, or what he is doing. There's an example below; could you explain what stat_cliente is doing? for(int i = 0; i < Config.CLIENTES; i++){ int stat_cliente; waitpid(Ind.pid_clientes[i],…
Andrejcc
  • 134
  • 8
1
vote
0 answers

Why does waitpid hang and not reap all child processes?

I'm attempting to simulate a shell processing foreground commands but I'm running into trouble when it comes to reaping child processes. I spawn multiple processes using fork in the following code. while (currCmdListNode !=…
RJ Stank
  • 31
  • 2
1
vote
0 answers

How do I go about mapping a pid_t to a struct?

I want to map a pid_t returned by wait or waitpid to a struct of pipe file descriptors. In the example below I do that with linear search. Is there better way to do that without a linear search or even a hash table? Using a function provided by UNIX…
Klokat
  • 53
  • 2
1
vote
1 answer

Does child address space affect the parent's address space

I want to know by the example below if the child's address space affect the parent's address space. So will the parent get the changed value of the child to 15 or it will get the value 5. I learnd that child's address space is not affected by its…
Bre
  • 79
  • 2
  • 7
1
vote
1 answer

What is the idea behind the way the signals are used here?

While reading up and learning about signals, I found a program, that uses signals in a specific way. I tried understand it, but I am not sure, how all the parts of the code interact with another. Below is the above mentioned code and I added…
Imago
  • 521
  • 6
  • 29
1
vote
0 answers

How to wait for process to write to a file or exit?

I need to monitor a process -- with a known PID -- and react to it either exiting for good, or writing into a file in a known subdirectory. The file(s) may not initially exist. On BSD I would use kqueue specifying the different things I want to be…
Mikhail T.
  • 3,043
  • 3
  • 29
  • 46
1
vote
2 answers

SIGCHLD and fork + waitpid() in a library

I am writing a library that uses fork() and exec() to run external programs. The code in my library runs as a separate thread. The library thread needs to waitpid() on the forked process to know the exit code of the child process. Unfortunately if…
user2624119
  • 107
  • 2
  • 11
1
vote
2 answers

Get returned value of a child process without holding parent execution

I need to be able to get the returned value from a child process without having to hold the execution of the parent for it. Notice the a runtime error could happen in the child process. Here is my program that I'm trying to make: //In parent…
Ebram Shehata
  • 446
  • 5
  • 20