Re: does system() return a pid?
by Athanasius (Archbishop) on Oct 10, 2015 at 04:06 UTC
|
Hello sciguy,
Does the system() function return a value ... and is that value the PID of the child process?
What would be the point? The return value of a system call is received only after the child process has completed and exited.
Maybe you’re looking for threads? See perlthrtut. The Monastery also has some tutorials on threads: Threads, Multi-Processing, and Inter-Process Communication.
Hope that helps,
| [reply] |
Re: does system() return a pid?
by kcott (Archbishop) on Oct 10, 2015 at 04:17 UTC
|
G'day sciguy,
"... is that value the PID of the child process?"
As already pointed out, the answer is no; however, that's exactly what's returned (to the parent process) by fork. Perhaps that's what you were thinking of or looking for.
| [reply] |
|
|
Thanks. Any documentation I could read told me nothing. fork() makes sense.
| [reply] |
|
|
"Any documentation I could read ..."
I assume from this statement that there's some documention you can't read (or, more likely, find or access).
Here's some options:
With internet access:
Without internet access, the perldoc utility is still available from the command line.
It should give you the documentation for whatever version of Perl you're using.
At least the first, but probably both, of these should work for you:
- $ perldoc perldoc
- $ man perldoc
| [reply] [d/l] [select] |
Re: does system() return a pid?
by Anonymous Monk on Oct 10, 2015 at 03:33 UTC
|
what do the docs say? [doc://system]->system Ctrl+F "return" 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) | [reply] [d/l] |
Re: does system() return a pid?
by ikegami (Patriarch) on Oct 11, 2015 at 03:09 UTC
|
On Windows and only there, the special calling convention system(1, ...) spawns a process and returns immediately. The child process's PID is returned.
All the other ways of calling system wait for the child to finish and reaps it. It would make no sense for them to return the PID of a process that no longer exists, so they do not return the child's PID.
| [reply] [d/l] [select] |
A reply falls below the community's threshold of quality. You may see it by logging in. |
Re: does system() return a pid?
by Laurent_R (Canon) on Oct 10, 2015 at 10:45 UTC
|
Does the system() function return a value (outside of the expected output to stdout)?
The system function does not return expected output to stdout, but the exit status of the command.
If you want to retrieve the external command expected output, you would have to use the backticks, for example:
my $output = `$system_command`;
or the qx operator.
| [reply] [d/l] |
Re: does system() return a pid?
by karlgoethebier (Abbot) on Oct 10, 2015 at 18:07 UTC
|
| [reply] |