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
1 answer

How to fork, wait on and kill processes in a platform-independent way?

I have some C code which uses fork()+exec(), wait() (or waitpid()) and kill() - and assumes they exist after including the relevant POSIX headers. Now, I want to make this code as multi-platform as possible - with minimal changes. So, no…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
0
votes
2 answers

wait(NULL) is not waiting till forked process is finished

This is the function that executes commands in a child process using system(). But once command completes execution it is expected to stop. Yet, on running ps command, I find new a.out process running. The program was supposed to wait for child to…
Ankush K
  • 334
  • 3
  • 13
0
votes
1 answer

Problem to understand how it works theses processes

Good evening, I'm programming and testing some things about processes in C with fork() and waitpid() system calls. I understand the behavior with the global variable, but I don't understand why when the second process is finished and back in the…
0
votes
2 answers

Using wait() vs waitpid() in c

So I'm trying to traverse a directory(and subdirectories) and create new processes to sort files and traverse subdirectories. However, I'm having a little trouble understanding how useful my code will be. To my understanding, wait() will sleep the…
Devin M
  • 5
  • 1
  • 4
0
votes
2 answers

How to get the return value of child process to its parent which was created using exec?

I have seen similar questions here and here. The answers suggest to use WEXITSTATUS. But according to man page of WAIT(2), it has a limitation. It says: WEXITSTATUS(wstatus) returns the exit status of the child. This consists of the…
psin
  • 59
  • 8
0
votes
2 answers

WIFSIGNALED returns false even if I send a signal with the kill command on Linux(Mint 18.3)

The problem: I need to print the kill signal received by a process, For example: If I send a *kill -15 1245* where 1245 is the pid of my process, my program should print something like "Process killed by signal 15", but even If I send a *kill…
0
votes
0 answers

how to wait on children and grandchildren processes

if(pid==0){ //child1 pid = fork(); if(pid==0){//child1 of child1 print("I am child 1 of child 1"); } else{//child1 pid = fork(); if(pid==0){//child 2 of child 1 print("I am child 2 of child 1"); …
Mitch Lew
  • 1
  • 1
0
votes
0 answers

How can Execl return but WIFEXITED and WEXITSTATUS don't indicate an error?

I am executing a binary with execl. This is all working OK, waitpid returns a correct pid, WIFEXITED(pidstatus) gives a 1 and WEXITSTATUS(pidstatus) a 0. Now I change the permissions for that binary to restrict its access. The binary is not being…
Lieuwe
  • 1,734
  • 2
  • 27
  • 41
0
votes
1 answer

Following xv6/Linux forking and waitpid processes

int main() { int count = 0; int pid; if ( !(pid=fork())) { while (((count<2) && (pid=fork()) ) { count++; printf("%d",count) } if(count>0) { printf("%d", count); …
Aleka
  • 242
  • 1
  • 15
0
votes
1 answer

Wait for all child processes avoiding the suspended processes

I'm trying to write a shell and I came across this problem: after I run the fork() and execute the commands, in the main process I wait for all child processes like this: while (wait(NULL) > 0); But when I try to suspend a child process, the main…
Emil Terman
  • 526
  • 4
  • 22
0
votes
1 answer

How to properly pass a killed child process's exit state up to the shell?

(I'm developing a simple expect-like program.) For example I have a program prog1.c which fork() and exec() another program prog2. When prog2 is killed by a signal (e.g. SIGPIPE), prog1 can get its exit state with waitpid(), WIFSIGNALED() and…
pynexj
  • 19,215
  • 5
  • 38
  • 56
0
votes
1 answer

Could not understand the output from the code

I wrote the following code and ran it for a couple times. But every time the result is different. #include #include #include int main(int argc, char **argv) { pid_t id; int status; while (--argc &&…
kww
  • 411
  • 4
  • 12
  • 21
0
votes
1 answer

How to wait a subchild and a parent before executing process?

Here is how my program articulates: there is a parent that forks a child and this child forks itself another child. So There is a parent, a child and a subchild (i.e. the parent of this subchild is the child). The child execute a command with…
SugarMouse
  • 131
  • 3
  • 9
0
votes
1 answer

Changing Parameters of waitpid()

I'm wondering if you can change the parameters of waitpid() At the moment I require continuous variable output ( 0.50 ) to be what is printed. However given that waitpid() only accepts integers when I try and printout it gives me 0. Unsure how to…
Dreeww
  • 93
  • 6
0
votes
1 answer

Linux C, waitpid() is unblocked by handled signals with return value -1 and errno 5

I ran into this problem a few hours ago. Even though I have fixed it, I simply don't understand why this happens. signal(SIGHUP, sighupHandler); . . . // sync with child by getting a char written by child fgetc(pipe_in); close(pipe_in); int…
Katharine
  • 1
  • 1