system() exit code

From: Stephen Morgan (
Date: 05/15/04

  • Next message: David A. Ferguson: "How to execute from remote NFS?"
    Date: Fri, 14 May 2004 18:18:03 -0500

    Hi all,

    This script, call it "st"

          #! /bin/sh
          exit 123

    exits with exit code of 123, as it should. However, this C code:

          int rc;
          rc = system("/root/yada/yada/st");
          printf("return code is: %d\n", rc);

    prints "return code is: 31488" which is 123 shifted left 8 bits. I've
    tried this with a few values and the 8-bit shift is consistent.

    Is this normal behavior for the system() function, and if so, is it
    documented somewhere? Before I commit to code that relies on this behavior,
    I'd like to know that it's reliable :-)

    Thanks for your help,

    Stephen Morgan

  • Next message: David A. Ferguson: "How to execute from remote NFS?"

    Relevant Pages

    • Re: Mutiple fork return status
      ... from a script you can obtain the exit code of any background process you spawned with the "wait" builtin, it will return the process' exit code as its own or 127 in case of errors try this sequence of commands, they are picked from memory but should be correct: ... # echo $? ... if you issue a "wait" while the process you are inquiring about is still running, the script will pause until the process in question exits by itself or is terminated. ... you can get more info about the "wait" builtin in the docs for the shell of your choice. ...
    • incorrect old gcc exit code
      ... it is that it returns 0 always, no matter succeeded it in compiling or ... So no surprise configure script fails wherever it uses gcc to ... exits with a proper exit code: ...
    • Re: Yast2 Runlevel editor. Waiting for children
      ... > |seems to wait for child processes from the init script to finish before ... > |it will return the parent's exit code. ... > Your daemon is not correctly written then. ...
    • Re: ssh in bash script
      ... >from shell prompt I can: ... >back at prompt in host1. ... >how to make it continue on in the script? ... >can I indeed just capture the exit code for a return value that I can ...
    • SUMMARY: rsh and exit codes
      ... is showing the results of the rsh command. ... it does have the ability to return the exit code. ... I have a small script, that has a "exit 1" in it. ... If I run the command locally then do a echo $? ...