Re: Return Value from Background System Call



Ben Morrow <benmorrow@xxxxxxxxxxxxx> writes:

Quoth Sherm Pendley <spamtrap@xxxxxxxxxxx>:

The meaning of a 0 exit status has to be interpreted in the context of the
launched app. For many apps, a 0 exit status is used to indicate failure of
a different sort than a general failure to execute the app,

I think you are getting confused here. A 0 exit status indicates
success...

No, it means that either main() ended in return 0, or exit(0) was called else-
where in the child app. The meaning of a particular value varies from app to
app and has not been standardized.

gcc only exits with 0 if it was successful.

OK, I stand corrected. A bogus example doesn't change my point though - a
value of 0 returned from system() does not necessarily indicate no errors from
the child. It indicates that the child returned 0, and the meaning of that 0
can vary.

Also keep in mind that the exit status of a program is whatever value is
returned from exit() or main(). Since you're launching this app in the
background and it's still running, that's probably why you're getting all
zeroes - you can't get an exit status from an app until it actually exits.

Please read the docs for the functions you are talking about. system
does not return until the command has exitted. Adding an & doesn't
change that.

I *have* read those docs, many times over the past ten years. I read them
again before posting. I meant to say the same thing you said, although I
didn't express it nearly so well. The "so what you're getting is the exit
status of the shell that launched your background app" at the end of the
quoted paragraph is implicit; I should have spelled it out to avoid this
confusion.

However, it *does* make system execute the command via a
shell instead of directly, and it is the shell which is exitting with 0,

One-argument system() will *always* execute its command via a shell. To
bypass shell command parsing and execute a program directly, one uses the
multi-argument form of system().

What the & at the end of the command does is change how the called shell
behaves. Instead of waiting for the command to finish and propagating its
exit status upward, the shell returns 0 immediately to indicate that the
command was successfully launched in the background.

I would advise the OP to fork/exec manually in Perl, as then you can see
what is actually happening.

Good advice.

sherm--

--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
.



Relevant Pages

  • Re: Vanishing threads in shell-script-started process on solaris 10
    ... Originally, app ... I saw all the daemons running with all their threads intact ... Next I tried launching the daemons from bourne shell command line as ...
    (comp.unix.solaris)
  • Re: How to build "Kiosk" application in vb.net
    ... I've set up a .Net app as a shell before, to test, and it worked fine. ... > What happens when I exit my app - will the pc shutdown or do I need to ...
    (microsoft.public.dotnet.languages.vb)
  • Re: custom shell starts before all services loaded
    ... Do you just want to launch your shell app and know when user input is available in it? ... You may end up launching a very small app as your shell. ...
    (microsoft.public.windowsxp.embedded)
  • Re: Auto Restart a Custom Shell on termination
    ... When I deal with different shells for Windows OSes I also prefer writing my own agent app that will take care of launching whatever ... - have a peice of code in your custom shell app to launch explorer.exe ... > I'm still wondering why this functionality do not work for your shell also. ...
    (microsoft.public.windowsxp.embedded)
  • Re: sqlce resources not released on application.exit()?
    ... The correct way to shut down is to exit the Main function. ... Chris Tacke, Embedded MVP ... > the app was using immediately every time. ... >> 3.5 Query Analyzer no longer opens the database for exclusive access. ...
    (microsoft.public.dotnet.framework.compactframework)