GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
System::Command::Reaper(3) User Contributed Perl Documentation System::Command::Reaper(3)

System::Command::Reaper - Reap processes started by System::Command

version 1.121

This class is used for internal purposes. Move along, nothing to see here.

The System::Command objects delegate the reaping of child processes to System::Command::Reaper objects. This allows a user to create a System::Command and discard it after having obtained one or more references to its handles connected to the child process.

The typical use case looks like this:

    my $fh = System::Command->new( @cmd )->stdout();

The child process is reaped either through a direct call to "close()" or when the command object and all its handles have been destroyed, thus avoiding zombies (which would be reaped by the system at the end of the main program).

This is possible thanks to the following reference graph:

        System::Command
         |   |   |  ^|
         v   v   v  !|
        in out err  !|
        ^|  ^|  ^|  !|
        !v  !v  !v  !v
    System::Command::Reaper

Legend: | normal ref ! weak ref

The System::Command::Reaper object acts as a sentinel, that takes care of reaping the child process when the original System::Command and its filehandles have been destroyed (or when System::Command "close()" method is being called).

System::Command::Reaper supports the following methods:

    my $reaper = System::Command::Reaper->new( $cmd, \%extra );

Create a new System::Command::Reaper object attached to the System::Command object passed as a parameter.

An optional hash reference can be used to pass extra attributes to the object.

    $reaper->close();

Close all the opened filehandles of the main System::Command object, reaps the child process, and updates the main object with the status information of the child process.

"DESTROY" calls "close()" when the sentinel is being destroyed.

    if ( $reaper->is_terminated ) {...}

Returns a true value if the underlying process was terminated.

If the process was indeed terminated, collects exit status, etc.

The attributes of a System::Command::Reaper object are also accessible through a number of accessors.

The object returned by "new()" will have the following attributes defined (as copied from the System::Command object that created the reaper):

pid
The PID of the underlying command.
stdin
A filehandle opened in write mode to the child process' standard input.
stdout
A filehandle opened in read mode to the child process' standard output.
stderr
A filehandle opened in read mode to the child process' standard error output.

After the call to "close()" or after "is_terminated()" returns true, the following attributes will be defined:

exit
The exit status of the underlying command.
core
A boolean value indicating if the command dumped core.
signal
The signal, if any, that killed the command.

Philippe Bruhat (BooK), "<book at cpan.org>"

This scheme owes a lot to Vincent Pit who on #perlfr provided the general idea (use a proxy to delay object destruction and child process reaping) with code examples, which I then adapted to my needs.

Copyright 2010-2016 Philippe Bruhat (BooK), all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
2020-06-03 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.