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

Waitpid does not continue after tracee stopped

I using ptrace to attach for process and then continue the process until tracee has been stopped (got SIGSTOP/SIGTRAP) ,I wait for that with waitpid . Usually that work fine, but sometime I see that even tracee has been stopped, waitpid (the second…
yfr24493AzzrggAcom
  • 159
  • 1
  • 2
  • 13
0
votes
0 answers

Using waitpid() to wait until foreground process terminates in C

I have token[0] variable that determines whether the input cmd is foreground process or background process. When token[0] is '&' it means it is background process and if it is not, it means it is foreground process. I want to print pid if it is…
dkssud
  • 3
  • 4
0
votes
0 answers

Linux SIGSTOP causes waitpid to continue

I wrote a shell program for linux, and created the following code for pipe command: void PipeCommand::execute() { jobs_list->removeFinishedJobs(); if(signal(SIGTSTP , ctrlZHandlerPipe)==SIG_ERR) { perror("smash error: failed to set ctrl-Z…
user2207686
  • 107
  • 1
  • 8
0
votes
0 answers

How do I make the parents processes wait for the children to finish using waitpid?

I want to make the parent processes (P1 and P2) wait for their respective child processes(P3 and P4) to terminate using waitpid (basically, parent processes can only terminate after the children terminates). Here's the code below. I'm portuguese,…
0
votes
1 answer

Proper way to use execlp and execvp while reporting exit status in C

I'm a student studying C and how to create processes using fork() Can you please explain what is the difference between these two codes because I've tried the both and they didn't work as expected. child = fork(); child1 = fork(); if (child == 0 &&…
CSE_Husky
  • 19
  • 2
0
votes
1 answer

How does parent process convert child process exit code to status code?

When I run the following code (headers and main entry ommitted) void fork11() { pid_t pid[N]; int i; int child_status; for (i = 0; i < N; i++) if ((pid[i] = fork()) == 0) exit(100+i); /* Child */ for (i = N-1; i >=…
mzoz
  • 1,273
  • 1
  • 14
  • 28
0
votes
2 answers

Get signal when tid status change

There is a way to look when pid/tid status change with waitpid but this is blocking function. I want to monitor all threads in specific pid and get signal when one of them change and print the tid. For now I open threads as count of threads in that…
paramikoooo
  • 177
  • 2
  • 16
0
votes
1 answer

forking, waitpid problems in c

For some reason this code executes the parental commands immediately, terminating my semaphores and screwing up my flow control of other programs. Can anyone tell me why the waitpid() isnt working? //Create child processes pid = fork(); if(pid <…
Josh
  • 657
  • 3
  • 15
  • 30
0
votes
1 answer

How to use `waitpid` to wait for a process in Rust?

I am trying to implement a merge sort using processes but I have a problem using the waitpid function: extern crate nix; extern crate rand; use nix::sys::wait::WaitStatus; use rand::Rng; use std::io; use std::process::exit; use…
Mateusz Piwowarski
  • 559
  • 1
  • 6
  • 15
0
votes
2 answers

Check for exited child processes in POSIX?

I'm trying to write a program that checks for exited child processes and restarts them if they have exited. It needs to restart the processes as they exit, without waiting for any other processes to have exited. I'm a little lost. Here's the code…
Cuthbert
  • 2,908
  • 5
  • 33
  • 60
0
votes
0 answers

When does waitpid() call return a value different from the pid (>0) passed?

These are from the documentation on waitpid() https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html About the pid parameter If pid is greater than 0, it specifies the process ID of a single child process for which status is…
0
votes
1 answer

A Query regarding the value of Exit Status of Child Process Created with fork()

Just have a query about Status of Child processes created with fork() #include #include #include #include #include int main (){ int pid; int status; printf("Parent: %d\n",…
0
votes
0 answers

why WIFSIGNALED is false if i kill the process with SIGPIPE + why exit code 256?

The program consists of 2 parts (i was asked to use pipe): A. manager - that creates processes that will help him calculate how many instances of a particular char are in the file. B. Count - Calculates how many instances there are in the file and…
0
votes
0 answers

How to break the child-process in such a way that he wouldn't become a zombie-process?

There is a small script that listens to the port. When somebody connected, the process forks. The problem is that when the child process close, it does not close correctly, but becomes a zombie process. I also want to add that it is important for…
Roman Andreev
  • 444
  • 3
  • 6
  • 18
0
votes
1 answer

Child process not exiting with fork()

I am creating a simple Linux command shell in C. I am having trouble understanding where my code is having problems. "commands" is a list of strings of Linux commands that I want to be executed concurrently as the children processes of one parent.…
M. Rosenlof
  • 112
  • 8