views:

150

answers:

1

The system() function will launch a new process from C and a Perl script.

What exactly are the differences between processes called by system() in C and from Perl scripts, in terms of representation of error codes?

+7  A: 

A little research brings up:

The return value is the exit status of the program as returned by the wait call. To get the actual exit value, shift right by eight (see below). See also "exec". This is not what you want to use to capture the output from a command, for that you should use merely backticks or qx//, as described in "STRING" in perlop. Return value of -1 indicates a failure to start the program or an error of the wait(2) system call (inspect $! for the reason).

And the docs of wait say:

Behaves like the wait(2) system call on your system: it waits for a child process to terminate and returns the pid of the deceased process, or -1 if there are no child processes. The status is returned in $? and ${^CHILD_ERROR_NATIVE} . Note that a return value of -1 could mean that child processes are being automatically reaped, as described in perlipc.


Sources: This was taken from perldoc. Here's a tutorial on system in Perl.

Eli Bendersky
@eliben, could you please provide me some more information or some link to work on these in detail
Sachin Chourasiya
@Sachin: linked to the sources
Eli Bendersky
The docs for C `system()` say exactly the same -- it returns -1 on failure to fork, and the result of `wait()` otherwise.
hobbs
I hate links to spammy about.com
Sinan Ünür