NAME

Proc::Simple -- launch and control background processes

SYNOPSIS

use Proc::Simple;

$myproc = Proc::Simple->new();        # Create a new process object

$myproc->start("shell-command-line"); # Launch a shell process
$myproc->start(sub { ... });          # Launch a perl subroutine
$myproc->start(\&subroutine);         # Launch a perl subroutine

$running = $myproc->poll();           # Poll Running Process

$myproc->kill();                      # Kill Process (SIGTERM)


$myproc->kill("SIGUSR1");             # Send specified signal


Proc::Simple->debug($level);          # Turn debug on

DESCRIPTION

The Proc::Simple package provides objects that model real-life processes from a user's point of view. A new process object is created by

$myproc = Proc::Simple->new();

Either shell-like command lines or references to perl subroutines can be specified for launching a process in background. A 10-second sleep process, for example, can be started via the shell as

$myproc->start("sleep 10");

or, as a perl subroutine, with

$myproc->start(sub { sleep(10); });

The start Method returns immediately after starting the specified process in background, i.e. non-blocking mode. It returns 1 if the process has been launched sucessfully and 0 if not.

The poll method checks if the process is still running

$running = $myproc->poll();

and returns 1 if it is, 0 if it's not. Finally,

$myproc->kill();

terminates the process by sending it the SIGTERM signal. As an option, another signal can be specified.

$myproc->kill("SIGUSR1");

sends the SIGUSR1 signal to the running process. kill returns 1 if it succeeds in sending the signal, 0 if it doesn't.

NOTE

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.

AUTHOR

Michael Schilli <schilli@tep.e-technik.tu-muenchen.de>