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

the meaning for exit status of the child process

Have some code like this: unsigned pid = waitpid(mPid, &status, WNOHANG); mExitStatus = WEXITSTATUS(status); Get the debug print for the variable like: mExitStatus = 15 status = 3840 For "mExitStatus = WEXITSTATUS(status)", I got following…
thundium
  • 995
  • 4
  • 12
  • 30
0
votes
1 answer

getting exit status from child process in c

I can not figure out what I have wrong with this code. This is C on a linux box. What it should do is kill all the child processes I created, wait for the all to quit and then print out a line for each child with the pid, process number (I create),…
0
votes
0 answers

Early call of waitpid does not collect exit status correctly

I am using the following code to fork a process and signal it to stop later. #include #include #include #include #include using namespace std; sig_atomic_t stopFlag = 0; void…
PowerGnom
  • 37
  • 6
0
votes
0 answers

strerror(errno) used after waitpid. what should be expected result from strerror?

I tried with strerror(errno) get the waitpid() result string. I checked the status string in both conditions: 1) Child is running by adding `sleep(30)` in child process 2) Without `sleep(30)` in child I got the below displays from…
kapilddit
  • 1,729
  • 4
  • 26
  • 51
0
votes
1 answer

C: 'run' command using waitpid & command line input

I'm trying to write, as part of my code, a function so that a user can type shell> run date //Line of user input Mon Jan 19 11:51:57 EST 2009 //Printed by program shell: process 348 exited normally with status 0 The user just types 'run date'…
user3295674
  • 893
  • 5
  • 19
  • 42
0
votes
2 answers

_exit(), fork() and waitpid() system calls

So, I'm exiting from the child thread back to the parent. I am using the _exit() system call. I was wondering a few things. One was what parameter for the _exit for my child. Here is the code that my child process is executing: printf("\n****Child…
pmac89
  • 418
  • 1
  • 6
  • 23
0
votes
1 answer

waitpid does not appear to be wating

I have a simple function - its purpose is to copy a file to a .old before overwriting it. Because i'm lazy (and an answer on here suggested it) I fork and use cp to do the work. Then i call waitpid and check the return codes. The code calling this…
Hector
  • 1,170
  • 2
  • 10
  • 27
0
votes
1 answer

How to safely `waitpid()` in a plugin with `SIGCHLD` handler calling `wait()` setup in the main program

I am writing a module for a toolkit which need to execute some sub processes and read their output. However, the main program that uses the toolkit may also spawn some sub processes and set up a signal handler for SIGCHLD which calls wait(NULL) to…
yuyichao
  • 768
  • 6
  • 28
0
votes
1 answer

Using Forks with waitpid

Are there 3 child processes and 1 parent process? What does the two different waitpid do, and why are there two of them? int main() { pid_t pid; int status, counter = 4; while(counter > 0) { pid = fork(); if(pid) …
0
votes
1 answer

non-root ptrace/waitpid on a non-child

This is a follow up/modification of my qn : Ptrace/wait on a non child How do I ptrace or wait on a process that is not a child AND the process that waits is not a root user . I tried to be in the same group, still doesnt work [ operation not…
resultsway
  • 12,299
  • 7
  • 36
  • 43
0
votes
2 answers

Ptrace/wait on a non child

int Enable ( int pid) { int status; #if 1 { printf ( "child pid = %d \n", pid ); long ret = ptrace (PTRACE_ATTACH, pid, NULL, NULL); do { int w = waitpid(-1, &status, 0); if (w == -1) { …
resultsway
  • 12,299
  • 7
  • 36
  • 43
0
votes
1 answer

Can't store information in a global variable when suspending a 2-pipe function in a mini-shell

I am writing a mini-shell and I encounter a problem in job control. I cannot retrieve the data in the main function and even in the bottom of run_command. I would like to know how i can store and successfully retrieve the information in the…
0
votes
0 answers

Signal and waitpid coexistence

I have the following question: can I use a signal handler for SIGCHLD and at specific places use waitpid(3) instead? Here is my scenario: I start a daemon process that listens on a socket (at this point it's irrelevant if it's a TCP or a UNIX…
mamalos
  • 97
  • 10
0
votes
1 answer

Unusual signal numbers from WTERMSIG macro after waitpid()

I am seeing unusual signal numbers (for example 50, 80 or 117) from the following code when waiting for a child process to terminate. I am only seeing this from one particular child process, and I have no access to the process source code and it…
trojanfoe
  • 120,358
  • 21
  • 212
  • 242
0
votes
2 answers

waitpid(pid, status, options) not always setting status

I'm working on replicating shell pipes for an assignment. I had the pipeline all working (and have not since changed the pipeline code, so that is known to work), but still needed to terminate the pipeline in the event of an execution failure in…
C. Warren Dale
  • 184
  • 2
  • 11
1 2 3
19
20