LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-06-2007, 10:46 PM   #1
PatrickNew
Senior Member
 
Registered: Jan 2006
Location: Charleston, SC, USA
Distribution: Debian, Gentoo, Ubuntu, RHEL
Posts: 1,148
Blog Entries: 1

Rep: Reputation: 48
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.
 
Old 02-07-2007, 04:35 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
'load average' return values from sysinfo() bulliver Programming 4 04-05-2005 10:02 PM
Is it possible to use system() and get the return value from the system call newguy21 Programming 1 08-11-2004 01:37 PM
How to use return values from system functions? kpachopoulos Programming 2 07-30-2004 03:09 AM
How to return values into an array using awk Helene Programming 1 05-01-2004 10:05 PM
How can get values return from a system call quenn Programming 1 09-16-2003 11:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration