c - waitpid - WIFEXITED returning 0 although child exited normally -


I am writing a program that gives birth to the hair process, and call waitpid The waiting code for the child process is below:

  // fork & amp; Exec to child pid_t pid = fork (); If (pid == -1) // Here is the error handling code ** ** ** triggered if (! Pid) {// binary_invocation is an array of child process program and its argument execv (args.binary_invocation [0], (four * const *) args.binary_invocation); // Here is some error handling code that is not ** ** triggered} and {int condition = 0; Pid_t res = waitpid (pid, and position, 0); // Here I see that pid_t is a positive integer & gt; Meaning of 0 and position 11, which means WIFEXITED (position) is 0. // It triggers a warning in my program output. } The value of   

waitpid page WIFEXITED :

  returns the right for WIFEXITED (status) If the child ends normally, then by calling the exit (3) or _ext (2), or returning to the main ().   

Which means that I want to return an integer! = 0 on success, which is not happening in the execution of my program, because I follow WIFEXITED == 0

However, from the command line only Is the program executing results in $? == 0 , and starts with the results of GDB:

  [inferior 1 (process 31934) normally passed)   

The program normally behaves except for the trigger warning, from which I think that something else is going on here, I am missing.

Edit:
Recommended below in comments, if the child is terminated by the default, and in fact, WifiSglad (status) 1 returns, and WTERMSIG (status) return 11, which is the SIGSEGV .

I do not understand, this is the reason why a call will be unsuccessful with a Segfault via execution, while the same call through GDB, or a shell will be successful?

ADIT 2:
The behavior of my application is very much dependent on the behavior of hair procedure, especially in a file to the child __feed__ (district) In the declared function, . waitpid after the call return, this file exists and is produced correctly which means that in some other district I would be out of my control somewhere else is. returned > >

or wait for on UNIX and Linux systems = "text">

(or any other wait of the variants) is the structure:

  bits 0-6 signal number which means that The reason for the baby to get out, or 0177 if the child is closed or if the child gets out without a signal 7 1 If the core is dumped, the other 0 8-15 is less than 8 beet value Price has been passed to explore / extract or returned by the main, or to stop / release / continue the child due to that signal   

(Note that Positrix bits Does not define, only macros, but at least Linux, Mac OS X / IOS and Solaris are the bit definitions used by. Keep in mind that waitpid if you want it to be WUNTRACED Flag and its If you pass A, then returns returns for stop events only if you pass it to the WCONTINUED flag, then the event events.) 11 means that the child came out due to 11 signals, which is SIGSEGV is still, rather than Pausix, traditionally).

Either your program is giving invalid arguments to execv (which is a C library cover or some other around execve ) kernel-specific Call), or when you run execv and when you run it with a shell or a GDB, the child runs differently.

If you are on a system that is generating stress , execv sign, strace -f .

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -