Create a new instance of this class by writing
It takes no arguments.
Launches a new process.
The start() method can be used to launch both external programs
(like /bin/echo) or one of your self-defined subroutines
(like foo()) in a new process.
For an external program to be started, call
If you want to pass a couple of parameters to the launched program, theres two options: You can either pass them in one argument like in
or in several arguments like in
Just as in Perls function system(), theres a big difference between the two methods: If you provide one argument containing a blank-separated command line, your shell is going to process any meta-characters (if you choose to use some) before the process is actually launched:
will expand /etc/initt* to /etc/inittab before running the ls command. If, on the other hand, you say
the * will stay unexpanded, meaning youll look for a file with the literal name * (which is unlikely to exist on your system unless you deliberately create confusingly named files :). For more info on this, look up perldoc -f exec.
If, on the other hand, you want to start a Perl subroutine in the background, simply provide the function reference like
or supply an unnamed subroutine:
You can also provide additional parameters to be passed to the function:
The poll method checks if the process is still running
The kill() method:
terminates the process by sending it the SIGTERM signal. As an option, another signal can be specified.
Set a flag to determine whether the process attached
to this object should be killed when the object is
destroyed. By default, this flag is set to false.
The current value is returned.
Method to set the signal that will be sent to the
process when the object is destroyed (Assuming
kill_on_destroy is true). Returns the current setting.
Redirects stdout and/or stderr output to a file.
Specify undef to leave the stderr/stdout handles of the process alone.
Call this method before running the start method.
Returns the pid of the forked process associated with
Returns the start time() of the forked process associated with
Returns the stop time() of the forked process associated with
|DESTROY (Destructor)||Object destructor. This method is called when the object is destroyed (eg with undef or on exiting perl). If kill_on_destroy is true the process associated with the object is sent the signal_on_destroy signal (SIGTERM if undefined).|
|exit_status||Returns the exit status of the process as the $! variable indicates. If the process is still running, undef is returned.|
The wait method:
waits until the process is done and returns its exit status.
|debug||Switches debug messages on and off Proc::Simple::debug(1) switches them on, Proc::Simple::debug(0) keeps Proc::Simple quiet.|
|cleanup||Proc::Simple keeps around data of terminated processes, e.g. you can check via t0() and t1() how long a process ran, even if its long gone. Over time, this data keeps occupying more and more memory and if you have a long-running program, you might want to run Proc::Simple->cleanup() every once in a while to get rid of data pertaining to processes no longer in use.|
Please keep in mind that there is no guarantee that the SIGTERM signal really terminates a process. Processes can have signal handlers defined that avoid the shutdown. If in doubt, whether a process still exists, check it repeatedly with the poll routine after sending the signal.
If you pass a shell program to Proc::Simple, itll use exec() to launch it. As noted in Perls exec() manpage, simple commands for the one-argument version of exec() will be passed to execvp() directly, while commands containing characters like ; or * will be passed to a shell to make sure those get the shell expansion treatment.
This has the interesting side effect that if you launch something like
then youll see two processes in your process list:
$ ps auxww | grep womper mschilli 9126 11:21 0:00 sh -c ./womper * mschilli 9127 11:21 0:00 /usr/local/bin/perl -w ./womper ...
A regular kill() on the process PID would only kill the first process, but Proc::Simples kill() will use a negative signal and send it to the first process (9126). Since it has marked the process as a process group leader when it created it previously (via setsid()), this will cause both processes above to receive the signal sent by kill().
Tim Jenness <email@example.com>
Mark R. Southern <firstname.lastname@example.org>
worked on EXIT_STATUS tracking
Tobias Jahn <email@example.com>
added redirection to stdout/stderr
Clauss Strauch <Clauss_Strauch@aquila.fac.cs.cmu.edu> suggested the multi-arg start()-methods.
Chip Capelik contributed a patch with the wait() method.
Jeff Holt provided a patch for time tracking with t0() and t1().
Brad Cavanagh fixed RT33440 (unreliable $?)
1996, Mike Schilli <firstname.lastname@example.org>
Copyright 1996-2011 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
|perl v5.20.3||SIMPLE (3)||2012-11-17|