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

c - execl`d program doesn't give promt back

EDIT: THE QUESTION IS ANSWERED IN COMMENTS So, i'm studying pipes. Long story short, i have two programs: first program creates a pipe and two forks: first fork closes read descriptor and writes some stuff to write one (then closes it), second fork…
Anton Tretyakov
  • 303
  • 1
  • 9
2
votes
1 answer

Zombie process is not cleanup with waitpid call

I am watching the processes with htop and I see that child process stays as zombie even though I clean up with waitpid call. Any idea why this might happen? Thank you very much! #include #include #include #include…
Validus Oculus
  • 2,756
  • 1
  • 25
  • 34
2
votes
2 answers

waitpid does not give me consistent results

Edit: I should first clarify, when waitpid does not work, it does not work for all processes. As suggested I printed out the return value of waitpid and received interesting results. Firstly, during the unsuccessful runs, waitpid() returns 0 even…
2
votes
1 answer

How to fork only one child at a time

I am trying fork for the very first time. I have a file with list of integers and I want every line to fork off a child, the child processes the line and writes something in the output file. Basically the for loop starts with number of lines in the…
Fairy
  • 101
  • 2
  • 12
2
votes
2 answers

Parent doesn't wait for child processes to finish despite reaping

I am fully aware that there are tonnes of articles explaining the inner workings of parent-child process dynamics. I have gone through them and got my stuff working as I want it to function, almost. But there is one thing which is bugging me out…
User9102d82
  • 1,172
  • 9
  • 19
2
votes
2 answers

`waitpid()' always returns -1

I'm executing the code below and the call to waitpid() always returns -1, thus the code bellow ends with an infinite loop. The call works if I replace WNOHANG with 0. void execute(cmdLine* pCmdLine) { int status = 0; pid_t pid = fork(); …
Liavba
  • 75
  • 9
2
votes
1 answer

Waitpid acting as if in non-blocking mode

I am playing around with system calls in C and I am stuck trying to understand this program I made - int main(int argc, char* argv[]) { int a; char *args[]={"sleep"," 10",NULL}; a = fork(); int stat; if(a==0){ setpgid(getpid(),getpid()); …
Black Jack 21
  • 315
  • 4
  • 19
2
votes
1 answer

Killing a process once time limit exceeded

I've been working on the following code for quite some time, but can't really figure it out. The task is to read a terminal command and to run it every x seconds; if the command hasn't finished within the waiting time, we want to kill the process…
ximilianL
  • 23
  • 3
2
votes
2 answers

How to leave (interrupt) the waitpid() function?

Currently I am programming a shell and I use the waitpid() function for my children processes. I also installed a signal handler so I can trap the SIGINT (CTRL+C) signal. So what I want now is when someone presses the SIGINT (CTRL+C) signal it…
Nado Ba
  • 21
  • 1
2
votes
0 answers

Ptrace or waitpid gets stuck in C on macOS

I'd like to write a mini-debugger with ptrace on OS X. I want the parent process to make the child process run step by step. This is what I tried, but the program gets stuck sometimes, it seems to be in an infinite loop or to be frozen. #include…
Bilow
  • 2,194
  • 1
  • 19
  • 34
2
votes
1 answer

waitpid returns 0 when SIGINT (Crtl+c) on a children

I'm working in a terminal for an university work, but I'm having troubles when looking for finished children. I have a list in which i save the background processes and this works fine, but when i bring it to the foreground and i send him a SIGINT…
2
votes
1 answer

How does (waitpid((pid_t)-1, NULL, WNOHANG) keep track of child processes to be returned?

I am writing a program where multiple child processes can be created and the parent process continues to execute even while the child processes have not been terminated. However, once they are terminated, I want them to be printed before prompting…
shay13
  • 37
  • 1
  • 6
2
votes
1 answer

fork 100 processes at same time and sometimes some processes become zombie

I try to start 100 processes at the same time in the following code: int cnt = 0; void sig_handler(int signo) { pid_t pid; int stat; pid = wait(&stat); cout << "cnt:" << ++cnt << ", pid:" << pid << " signal:" << signo <<…
vinllen
  • 1,369
  • 2
  • 18
  • 36
2
votes
1 answer

Why my pipe ends only when i send a SIGINT

Basicaly, im writing a shell in C.. Im trying to implement the pipe feature, which is almost done: > ls | cat -e | wc | wc -l > 1 But i have a problem when trying to pipe a more slower/longer execution. Indeed, when i try to pipe the result of…
lifeguru42
  • 156
  • 1
  • 12
2
votes
1 answer

fork and waitpid in C

I have this piece of code, maybe I'm missing something: const int NPROCESSES = 32; pid_t pids[128]; for (int i = 0; i < NPROCESSES;i ++) { pids[i] = fork(); if (!pids[i]) { /*... other code ...*/ exit(0); } } for (int i…
user6171116