Questions tagged [wexitstatus]

16 questions
4
votes
1 answer

fork() and wait() in c while loop?

I have this small program in c and I am trying to understand how it works, it is a simple while loop that uses fork() and wait() to print out a few lines on the command line, I have commented to the best of my ability what I think is happening for…
user3545370
  • 205
  • 1
  • 4
  • 16
3
votes
2 answers

Strange behavior about WEXITSTATUS with `G++ 4.9.4`

This code snippet below does compiles, #include #include #include int main() { int ret = 0xFFFF; std::cout << WEXITSTATUS(ret); } whereas this code snippet does not compile indeed with G++…
John
  • 2,963
  • 11
  • 33
2
votes
2 answers

WEXITSTATUS(childStatus) returns 0 but waitpid returns -1

As far as I know if waitpid returns -1 then it is error condition. How it possible to get success (EXIT_SUCCUSS) from child process in WEXITSTATUS(childStatus)? What is the difference between childStatus in waitpid & return value from…
kapilddit
  • 1,729
  • 4
  • 26
  • 51
1
vote
0 answers

What is meaning of output of WEXITSTATUS on linux. Return status from waitpid for child process

What is the meaning of returning WEXITSTATUS on Linux if WEXITSTATUS is returning child process status as 170 and if WIFEXITED returns true?
1
vote
0 answers

Negative exit value with WEXITSTATUS

I have a child process that is designed to exit under certain conditions, I have used exit(-2). But after calling WEXITSTATUS the value is around 256. If I use exit(2) the proper value is returned by WEXITSTATUS. Any reason why using a negative…
1
vote
1 answer

Wrong exit code received from wexitstatus

I'm using PCNTL to multiprocess a big script in PHP on an ubuntu server. Here is the code ( simplified and commented ) function signalHandler($signo = null) { $pid = posix_getpid(); switch ($signo) { case SIGTERM: case…
Random
  • 3,158
  • 1
  • 15
  • 25
1
vote
3 answers

waitpid/wexitstatus returning 0 instead of correct return code

I have the helper function below, used to execute a command and get the return value on posix systems. I used to use popen, but it is impossible to get the return code of an application with popen if it runs and exits before popen/pclose gets a…
Mahmoud Al-Qudsi
  • 28,357
  • 12
  • 85
  • 125
0
votes
1 answer

is possible to get the exit status from the child of a child process in the parent

I try to get the exit code from a child of a child process in the parent process. If the process goes in the while loop to fork again i don't get the exit code. I tried some options for waitpid like WNOHANG but then the program hangs. Maybe what i…
0
votes
1 answer

Retrieving the total amount of processes from a fork() call using WEXITSTATUS

Looking at this post I do not understand Kaylum's answer. I have two questions. 1) S/he wants to use the variable "count" to count the total number of processes spawned (that is the total number of children grandchildren etc + original process)…
EFiore
  • 105
  • 1
  • 9
0
votes
2 answers

Forked 10 child processes, how can the parent process collect their return values?

I have to find the biggest value in an array of a 1000 numbers with 10 child processes (so that every one of them only checks a hundred values), and the parent only has to collect the data. I'm already done with the whole thing, but I'm stuck at…
SzajnIn
  • 81
  • 2
  • 7
0
votes
1 answer

how to cast status of type float to WEXITSTATUS

I have the code below, but I need that exit(status) return a float but WEXITSTATUS doesn't receive a float cause status must be int, so what's the solution please? scanf("%f%f",&f,&g); P = fork(); if(P == 0){ printf("\nje…
Hind Dev
  • 115
  • 2
  • 7
0
votes
1 answer

Not able to get waitpid() to return correct WEXITSTATUS for error condition

I have a command and some input that when run on the command line will return an error, with an associated error code of 1: $ foo bar [some useful error message...] $ echo $? 1 I am trying to catch this error code with waitpid(): ... char *proc_cmd…
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
0
votes
1 answer

status value in wait function and wexitstatus

I read this code in an implementation of the system function of unix (problem 8.22): int status; if (wait(&status) > 0) { if (WIFEXITED(status)) { return WEXITSTATUS(status); } else { …
teaLeef
  • 1,879
  • 2
  • 16
  • 26
0
votes
1 answer

Parsing WEXITSTATUS int-summed return code(s) in C via bitwise operation

I'm only a novice when it comes to bitwise math - if that's even the correct term - and was looking for a better way to do logic on an int-summed return code (as is standard for various Unix programs). I.e. the return code could be any combination…
CosmicDan
  • 61
  • 2
  • 9
0
votes
1 answer

how can i use wexitstatus to get the value more than 255

I can just speak a little English so I hope you can understand what I said. I fork a child process , then I do ADD in child process. EX: 56+48=104 If the value lower than 255 , I can use "wexitstatus(status)" to get the answer. But if the value…
1
2