[25962] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8181 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 17 14:05:35 2005

Date: Fri, 17 Jun 2005 11:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 17 Jun 2005     Volume: 10 Number: 8181

Today's topics:
    Re: Decorator pattern - IO::file <nobull@mail.com>
        How to kill a forked child process... <moritz.karbach@desy.de>
    Re: How to kill a forked child process... xhoster@gmail.com
    Re: How to kill a forked child process... <nobull@mail.com>
        Perl docs in CHM format? <slake2@ns.sympatico.ca>
    Re: Perl docs in CHM format? <1usa@llenroc.ude.invalid>
    Re: Perl docs in CHM format? <slake2@ns.sympatico.ca>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 17 Jun 2005 17:48:10 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Decorator pattern - IO::file
Message-Id: <d8uusb$53h$1@redhat2.bham.ac.uk>



bugbear wrote:

> Brian McCauley wrote:
> 
>> bugbear wrote:
>>
>>> I would (greatly) like to be able to do something a LOT
>>> like pipes, without using (well...) pipes.
>>>
>>> I simple want to be able to build sequence
>>> of filters (at least if they were on Unix
>>> they would be called filters)
>>
>>> It appears that I can achive this by embodying
>>> my filter code in the read() method of IO::file
>>> (actually, IO;:handle withing IO::file).
>>
>> You could do that - but you'd be better off using tied filehandles (if 
>> you need pre-5.8.x compatibility) or PerlIO layers otherwise.
>>
> 
> Thanks for the pointer.
> As far as I (and google ...) can find,
> Perl layers appear to be a 'C' thing.

Yes but there is a module PerlIO::via to let you write them in Perl 
using UPPERCASE methods rather as you do with tie()d things.

> Do you have any more help for me?

No much, I've never done this myself.

perldoc PerlIO::via



------------------------------

Date: Fri, 17 Jun 2005 18:26:09 +0200
From: Moritz Karbach <moritz.karbach@desy.de>
Subject: How to kill a forked child process...
Message-Id: <d8utj2$4tjhd$1@claire.desy.de>

 ...such that it doesn't become a zombie?

Hi,

I'm trying to implement something like this:

         parent
           |
           |
           |\  fork
           | \
           |  \
           |  | child calls an system command,
           |  | exec("foo");
           |  |
    fork  /|  |
         / |  |
        /  |  |
 watch- |  |  |
 dog    |  |  |
 kills  |  |  -
 foo    -  |
           |
           |

           
But everytime the watchdog kills the child, the child becomes a zombie. Is
there a way to prevent this?

Here is some code (the run-function of my Command-class, which handles
system calls):

sub runFork # ()
{
        my $this = shift;
        my $fh_child; # pipe to the child process running the command

        $pid = fork;
        die "cannot fork: $!\n" unless defined($pid);
        
        if ( $pid == 0 )
        {
                #
                # child (command branch)
                #
                my @temp     = ($EUID, $EGID);
                my $orig_uid = $UID;
                my $orig_gid = $GID;
                $EUID = $UID;
                $EGID = $GID;
                
                # Drop privileges
                $UID  = $orig_uid;
                $GID  = $orig_gid;
                
                # Make sure privs are really gone
                ($EUID, $EGID) = @temp;
                
                die "Can't drop privileges"
                     unless $UID == $EUID  && $GID eq $EGID;
                
                open(STDERR, ">&STDOUT") or die "Can't dup STDOUT: $!";
                
                $SIG{TTIN} = "IGNORE";
                $SIG{TTOU} = "IGNORE";
                $SIG{CHLD} = "IGNORE";
                $SIG{CLD} = "IGNORE";
                setpgrp(0,0);

                exec($this->{command}) or die ("cannot run program: $!");
                exit;
        }

        #
        # fork once more for the watchdog for the timeout
        #
        my $wdog_id;

        $wdog_id = fork;        
        die "cannot fork: $!\n" unless defined($wdog_id);

        if ( $wdog_id == 0 )
        { 
                #
                # child - watchdog branch
                #
                $SIG{TTIN} = "IGNORE";
                $SIG{TTOU} = "IGNORE";
                $SIG{CHLD} = "IGNORE";
                $SIG{CLD} = "IGNORE";                   
                setpgrp(0,0);

                sleep($this->{timeout});

                kill(-9, $pid);
                #`kill -9 $pid`;
                exit;
        }

        #
        # read output of the command
        #
        my @output = <$fh_child>;
        close($fh_child);
        $this->{output} = \@output;

        #
        # return value of the command
        #
        $this->{ret} = $?;
        my $sig = $this->{ret} & 127;

        #
        # if command succeeded, we don't need the watchdog any more: kill!
        #
        if ( defined($wdog_id) && $sig != 9 )
        {
                kill(-9, $wdog_id);
        }

        return $this->{ret};
}


------------------------------

Date: 17 Jun 2005 16:38:52 GMT
From: xhoster@gmail.com
Subject: Re: How to kill a forked child process...
Message-Id: <20050617123852.847$k9@newsreader.com>

Moritz Karbach <moritz.karbach@desy.de> wrote:
>
> But everytime the watchdog kills the child, the child becomes a zombie.
> Is there a way to prevent this?

perldoc -q zombie

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: Fri, 17 Jun 2005 17:36:38 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: How to kill a forked child process...
Message-Id: <d8uu6n$4sl$1@redhat2.bham.ac.uk>

Moritz Karbach wrote:
> ...such that it doesn't become a zombie?
> 
> Hi,
> 
> I'm trying to implement something like this:
> 
>          parent
>            |
>            |
>            |\  fork
>            | \
>            |  \
>            |  | child calls an system command,
>            |  | exec("foo");
>            |  |
>     fork  /|  |
>          / |  |
>         /  |  |
>  watch- |  |  |
>  dog    |  |  |
>  kills  |  |  -
>  foo    -  |
>            |
>            |
> 
>            
> But everytime the watchdog kills the child, the child becomes a zombie. Is
> there a way to prevent this?

The parent process of the child (not the sibling) must wait() or ignore 
$SIG{CHLD}.

Have the parent fork off the watchdog process, then have the watchdog 
fork-and-exec.

This doesn't really have anything to do with Perl, this is a Unix question.



------------------------------

Date: Fri, 17 Jun 2005 16:22:29 GMT
From: "Stephen Lake" <slake2@ns.sympatico.ca>
Subject: Perl docs in CHM format?
Message-Id: <9NCse.48454$Ph4.1275605@ursa-nb00s0.nbnet.nb.ca>

Can anyone tell me if the perl docs are available in Windows CHM Help file
format? I have looked with no success unless I was looking in the wrong
places.

If this question was asked already and answered then I appologize for
missing it.

Thanx




------------------------------

Date: Fri, 17 Jun 2005 16:34:12 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl docs in CHM format?
Message-Id: <Xns96787FDD6DE9Easu1cornelledu@127.0.0.1>

"Stephen Lake" <slake2@ns.sympatico.ca> wrote in
news:9NCse.48454$Ph4.1275605@ursa-nb00s0.nbnet.nb.ca: 

> Can anyone tell me if the perl docs are available in Windows CHM Help
> file format? I have looked with no success unless I was looking in the
> wrong places.
> 
> If this question was asked already and answered then I appologize for
> missing it.

<URL:http://www.google.com/search?q=perldoc+chm+format>

<URL:http://htmlhelp.berlios.de/books/chm.php>

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


------------------------------

Date: Fri, 17 Jun 2005 17:25:54 GMT
From: "Stephen Lake" <slake2@ns.sympatico.ca>
Subject: Re: Perl docs in CHM format?
Message-Id: <CIDse.48471$Ph4.1277376@ursa-nb00s0.nbnet.nb.ca>

For those interested I just found it in CHM here
http://htmlhelp.berlios.de/books/chm.php

haven't gone through it yet but there are a few files here for different
utilities and programs and languages (ie Python, g77, cpp, perl etc etc)

Just thought I would post this here in case others are interested in getting
it as well.




------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 8181
***************************************


home help back first fref pref prev next nref lref last post