Changeset 11649 in project


Ignore:
Timestamp:
08/15/08 20:14:52 (12 years ago)
Author:
Jim Ursetto
Message:

Changes applied for zbigniew (71.201.82.27) through svnwiki:

Add sample decoding of signal/exit status to (system) documentation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/Unit library

    r8642 r11649  
    612612Execute shell command. The functionality offered by this procedure
    613613depends on the capabilities of the host shell. If the forking of a subprocess
    614 failed, an exception is raised. Otherwise the return status of the
    615 subprocess is returned unaltered.
    616 
    617 
    618 
     614failed, an exception is raised.   Otherwise, the return status of the subprocess is returned unaltered.
     615
     616On a UNIX system, that value is the raw return value of waitpid(2), which contains signal, core dump and exit status.    It is 0 on success.  To pull out the signal number or exit status portably requires POSIX calls, but in a pinch you can use something like this:
     617
     618 ;; Returns two values: #t if the process exited normally or #f otherwise;
     619 ;; and either the exit status, or the signal number if terminated via signal.
     620 (define (process-status rc)
     621   (define (wait-signaled? x) (not (= 0 (bitwise-and x 127))))
     622   (define (wait-signal x) (bitwise-and x 127))
     623   (define (wait-exit-status x) (arithmetic-shift x -8))
     624   (if (wait-signaled? rc)
     625       (values #f (wait-signal rc))
     626       (values #t (wait-exit-status rc))))
     627
     628 #;> (process-status (system "exit 42"))
     629 #t
     630 42
    619631
    620632=== Execution time
Note: See TracChangeset for help on using the changeset viewer.