moderated >> Shielding system() from SIGINT

by Daniel E. Macks » Wed, 23 Mar 2005 00:32:47 GMT

I've got a perl script that uses system() to spawn a program that
should not be interrupted. I can't modify that subprogram itself, so I
currently do:

{
local $SIG{INT} = 'IGNORE';
system("some_thing");
}

That works (the perl process ignores SIGINT, preventing it from
getting to the some_thing process) but we want to be more friendly,
and let the user know why control-C didn't kill the process. How do I
catch the SIGINT and print a msg, but not propagate the sig to the
spawned process?

I thought I wanted:
local $SIG{INT} = sub { print "not interrupt allowed at this time\n" };
but that still results in my some_thing process aborting.

Interestingly, this appears to contradict perlfaq8 ("How do I make a
system() exit on control-C?"), which says I need two write a handler
in the parent to propagate the SIGINT To the system()'ed process.

I'm on OS X, using 5.8.1 (part of Apple's 10.3.x system) or 5.8.6
(compiled by Fink).

dan

--
Daniel Macks
XXXX@XXXXX.COM
http://www.netspace.org/~dmacks

moderated >> Shielding system() from SIGINT

by Daniel E. Macks » Sun, 27 Mar 2005 06:46:10 GMT


black nationalist. But
since it's the natural tendency for leaders to be jealous and look upon
a powerful figure like Graham with suspicion and envy, how is it
possible for him to come into a city and get all the cooperation of the
church leaders? Don't think because they're church leaders that they
don't have weaknesses that make them envious and jealous -- no,
everybody's got it. It's not an accident that when they want to choose a
cardinal, as Pope I over there in Rome, they get in a closet so you
can't hear them cussing and fighting and carrying on.

Billy Graham comes in preaching the gospel of Christ. He evangelizes the
gospel. He stirs everybody up, but he never tries to start a church. If
he came in trying to start a church, all the churches would be against
him. So, he just comes in talking about Christ and tells everybody who
gets Christ to go to any church where Christ is; and in this way the
church cooperates with him. So we're going to take a page from his book.

Our gospel is black nationalism. We're not trying to threaten the
existence of any organization, but we're spreading the gospel of black
nationalism. Anywhere there's a church that is also preaching and
practicing the gospel of black nationalism, join that church. If the
NAACP is preaching and practicing the gospel of black nationalism, join
the NAACP. If CORE is spreading and practicing the gospel of black
nationalism, join CORE. Join any organization that has a gospel that's
for the uplift of the black man. And when you get into it and see them
pussyfooting or compromising, pull out of it because that's not black
nationalism. We'll find another one.

And in this manner, the organizations will increase in number and in
quantity and in quality, and by August, it is then our intention to have
a black nationalist convention which will consist o

Similar Threads

1. SIGINT not blocked by system()?

I've got a multithreaded script in which I'd like to have my "worker"
threads ignore SIGINT (i.e. the main thread traps it and calls a sub to
cleanup nicely after all workers are done).  The workers do their thing
via system() calls, and my experience (using 5.8.8 at least) indicates
that SIGINT is being propogated to the worker threads' system() call
(even though it's locally ignored).

According to perlfaq8, system() is shielded from SIGINT:

-----------------------------------------------------------------------------
How do I make a system() exit on control-C?

You can't. You need to imitate the system() call (see perlipc for
sample code) and then have a signal handler for the INT signal that
passes the signal on to the subprocess.
-----------------------------------------------------------------------------

When CTRL-C is hit on the console, the following code will print
"Cleaning up..." and exits promptly.  I would have expected it to exit
after all threads have returned.


#!/usr/bin/perl -w
use strict;

use threads;

$SIG{INT} = \&cleanup;

foreach my $id ( 1..10 ) {
    threads->new( \&sleeper, $id );
}

sleep 60;

sub cleanup {
    print "Cleaning up\n";
    foreach my $thread ( threads->list() ) {
        $thread->join();
    }
    exit();
}

sub sleeper {
    my $id = shift;
    my $time = int( rand(30) );
    local $SIG{INT} = 'IGNORE';
    print "Thread $id sleeping for $time...\n";
    system( "sleep $time" );
    
    return;
}

2. handling SIGINT in a Tk application

3. Outputs stop ignoring SIGINT with Event.pm

Vital stats:
    Perl Version:            5.6.1
    Event.pm version:    0.85
    OS:                           Solaris 8 (Sparc)

I have a perl script that runs 24/7.  It uses Event.pm to control various
processes and commands.  To command it, I telnet into a particular port that
it listening on.  If during the session I type a ^C the process would
terminate.  I have attempted to ignore the ^C by two different methods:

    1.  $SIG{INT} = "IGNORE";
    2. Event->signal(signal => 'INT', cb => sub{});

In both cases, output to the telnet process stops, but the perl scripts still
responds to commands on the port.  If I break the connection and restablish
all is fine.

So, what do I have to do to reestablish output?

Thanx.

Brad



4. Running system command or batch file using system "[command]" - Perl

5. Some 'System Calls' was Capturing system call output value

On Friday, Nov 14, 2003, at 18:39 US/Pacific, Jerry Rocteur wrote:

> Beautiful drieux, what a sexy way to do a system call!!
>
> And I never knew about $host = hostname;.. What a neat trick..
>
> Keep 'em comin...

Wiggins is the one who deserves the point,
since he was the one with the reference
to Sys::Hostname, and when one sees such
things one should just do the

	perldoc Sys::Hostname

read the pod, copy and paste from the pod
the call that one needs and move on to
the next problem.

ciao
drieux

---

6. Reading RMS files on a OpenVMS system from a WIN32 system - Perl

7. Net FTP -- Size showing different results on AIX system and Linux system

To All:

This is my first post.  My name is Frank.  I have been using  Net FTP
to create an automated FTP process.  I developed it on an AIX box (AIX
5.2.0.7)  and now want to move it to our Linux box (Redhat).  The size
subroutine gives different results when running on the AIX version
Linux box.  On the AIX the size functions returns the size of the file
on the FTP while the call on the Linux box returns undefined.

I am calling the same FTP site each time and using the same version of
the script.  What else would need to be done to get these version in
sync??

Thanks!


Frank Bright
Univ. of the Arts
215.717.6081
 XXXX@XXXXX.COM 

8. System::DProf and system() - Perl