LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   system() and return values (https://www.linuxquestions.org/questions/programming-9/system-and-return-values-526265/)

PatrickNew 02-06-2007 10:46 PM

system() and return values
 
I'm writing an ncurses application that should call another ncurses app via system(). This is in C, btw. However, when I return at the end of main() in the called program, I actually return values rather than just saying "return 0".

Is there any way to get these return values through the return value of system()? I read that system should return 128+n where n is the return value of the command, but in experience this isn't happening.

wjevans_7d1@yahoo.co 02-07-2007 04:35 AM

If you want a quick and dirty answer, it's this: The system will return 256*n, not 128+n. But you don't want that; your call could have terminated not because the called program exited, but because it got killed or something.

If you want to do things right, try this command:

man 3 system

That will, in turn, direct you to try this command:

man 2 wait

In that man page, read about the various macros you can apply to the returned status to see whether it returned by exit, by signal, or whatever; and also which signal it was (if it was terminated by a signal), or what the return code was (if it exited).

Hope this helps.


All times are GMT -5. The time now is 08:01 AM.