Korn/Bourne shell return code precision

Korn/Bourne shell return code precision

Post by Brian Sach » Wed, 13 Apr 1994 22:38:53



From what I can tell, it appears that the Korn shell will only
handle 8 bit return codes.  Is there a way to detect return
codes greater than 256?  If a program returns a 16 bit return
code, are 8 bits lost?

Thanks for any info.

 
 
 

Korn/Bourne shell return code precision

Post by SIEV.. » Thu, 14 Apr 1994 08:44:05



>From what I can tell, it appears that the Korn shell will only
>handle 8 bit return codes.  Is there a way to detect return
>codes greater than 256?  If a program returns a 16 bit return
>code, are 8 bits lost?

here's a quote from the KSH man pages

            - return [n]
                 Causes a shell function or script to return to the
                 invoking script with the return status specified
                 by n.  The value will be the least significant 8
                                              ^^^^^^^^^^^^^^^^^^^
            >>>> bits of the specified status.      If n is omitted
                 then the return status is that of the last command
                 executed.  If return is invoked while not in a
                 function or a script, then it is the same as an
                 exit.

------------------------------------------------------------------------

/bin/sh on the other hand will 'return' very high vals from subroutines
but still will not exit higher than 255.

with /bin/ksh you will get nothing higher than 255 whether from a sub
return or an exit.

hope this helps...

 
 
 

Korn/Bourne shell return code precision

Post by Richard L. Hamilt » Thu, 14 Apr 1994 09:22:59




>From what I can tell, it appears that the Korn shell will only
>handle 8 bit return codes.  Is there a way to detect return
>codes greater than 256?  If a program returns a 16 bit return
>code, are 8 bits lost?

From my man page for wait(2) (SVR2, or UNIX PC v3.5)

   SYNOPSIS
        int wait (stat_log)
        int *stat_loc;

        int wait ((int *) 0)

[...]
        If stat_loc (taken as an integer) is non-zero, 16 bits of information
        called status are store in the low order 16 bits of the location
        pointed to by stat_loc.
[...]
               If the child process terminated due to an exit call, the low
               order 8 bits of status will be zero and the high order 8 bits
               will contain the low order 8 bits of the argument that the
               child process passed to exit; see exit(2).

So the return code will always be truncated to just the low-order 8 bits
passed to exit(2) by the called process, i.e. this is not just a limitation of
ksh.  On a machine with twos-complement binary notation, -1 would be gotten
back by the parent as 255 (within the 8 bit area available for that).  Newer
systems have macros such as WIFEXITED(), WEXITSTAT(), etc. defined in
<sys/wait.h> that test to see whether exited, signalled (killed), or
stopped are applicable, and if the macro that tests for one of those
shows true, a corresponding macro is available to extract the interesting
portion of the status info.

If 8 bits of status just isn't enough, you have to pass the data back in
a file or pipe, or with some sort of IPC.

I just tried this with ksh, and it holds.  Non-negative exit codes should
be mod 256, negative ones *may* vary according to how signed numbers are
implemented.
--
                      I compute, therefore I am.
My opinions are strictly by own, and should not be construed to represent
anyone else.

 
 
 

Korn/Bourne shell return code precision

Post by Barry Margol » Mon, 18 Apr 1994 15:28:03



>From what I can tell, it appears that the Korn shell will only
>handle 8 bit return codes.  Is there a way to detect return
>codes greater than 256?  If a program returns a 16 bit return
>code, are 8 bits lost?

That's because this is all that is returned to the parent process.  From
wait(2):

             Otherwise, the child process  terminated  due  to  a
             call  to  exit(2V).  The next byte contains the low-
             order 8 bits of the argument that the child  process
             passed to exit().
--
Barry Margolin
System Manager, Thinking Machines Corp.


 
 
 

1. Trying to run nohup from Korn shell but getting Bourne shell errors

Help! Duh!
I would like to run a process in background with nohup on a
SOLARIS 2.3. How can I get the korn shell script detectsetup
to be interpreted under ksh.

In Korn shell I attempted...

$ /bin/ksh -c "/usr/bin/nohup /export/home/setupin/detectsetup&"

$ [1]   15276

$ Sending output to nohup.out

Checking the process I find....

USER   PID    PPID COMMAND
pagein 15414     1 sh /export/home/setupin/detectsetup
                            ^
                           | Why not Korn shell

My nohup.out file errors indicate Bourne shell is interpreting Korn shell
script (doesn't understand integer or [[).      

2. Merry Xmas from 8lgm

3. Telling Bourne shell from Korn shell at start-up

4. Help! "/dev/lp" - problem with the new HP660 Deskjet

5. Caridge return in unix korn/bourne scripts

6. how to boot YDL without BootX?

7. Light Speed Bourne Shell! (was: Bourne shell tricks)

8. a faster way to gettimeofday?

9. best korn shell resources and is there a korn shell faq

10. How to pipe stderr to a command in Bourne or Korn shell

11. BOURNE/KORN Shell Compiler

12. bourne and korn shell incompatibilities

13. Looking for simple Bourne/Korn shell FIFO queue mechanism :-|