Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Kill a system process within the script

Reply
Thread Tools

Kill a system process within the script

 
 
Mav
Guest
Posts: n/a
 
      06-03-2004
Hi, all
I am trying to lanuch a command on my perl script using system call,
I wonder is that a way when someone hit Ctrl-Y, it will kill my
script,and also kill that system call process as well.

My script:

....
@args = ("doing something take a long time");

if (system(@args)==0) {
print "ok";
} else
print "something wrong";

Please help,
Thanks,
M
 
Reply With Quote
 
 
 
 
Gregory Toomey
Guest
Posts: n/a
 
      06-03-2004
Mav wrote:

> Hi, all
> I am trying to lanuch a command on my perl script using system call,
> I wonder is that a way when someone hit Ctrl-Y, it will kill my
> script,and also kill that system call process as well.


Huh? killing a process takes microseconds.

> My script:
>
> ...
> @args = ("doing something take a long time");
>
> if (system(@args)==0) {
> print "ok";
> } else
> print "something wrong";
>
> Please help,
> Thanks,
> M


Assuming linux/unix:
Try system("kill -SIGTERM $process") ; then
Try system("kill -SIGKILL $process")

where you set $process top the pid you want tokill.


gtoomey
 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      06-04-2004
Mav <> wrote in comp.lang.perl.misc:
> Hi, all
> I am trying to lanuch a command on my perl script using system call,
> I wonder is that a way when someone hit Ctrl-Y, it will kill my
> script,and also kill that system call process as well.
>
> My script:
>
> ...
> @args = ("doing something take a long time");
>
> if (system(@args)==0) {
> print "ok";
> } else
> print "something wrong";


I don't know what Ctrl-Y does in your system. An INT signal (as
created by Ctrl-C per default on Unix) is already treated the way
you want.

Anno
 
Reply With Quote
 
lee
Guest
Posts: n/a
 
      06-05-2004
Mav wrote:

> I am trying to lanuch a command on my perl script using system call,
> I wonder is that a way when someone hit Ctrl-Y, it will kill my
> script,and also kill that system call process as well.


Yes.

When you launch the process, note its process ID.

Then have your script "trap" the control character in question,
and when that character is received, call the system 'kill'
command
on the previously noted PID, as described by someone else on
this thread.

See, for example, perldoc -q signal:

Found in .... pod/perlfaq8 :
How do I trap control characters/signals?

$Interrupted = 0; # to ensure it has a value
$SIG{INT} = sub {
$Interrupted++;
syswrite(STDERR, "ouch\n", 5);
}


Lee Goddard
 
Reply With Quote
 
Mav
Guest
Posts: n/a
 
      06-14-2004
The script is running on the PC.
Once I launch the "system("Doing something take a long time");" from
my perl script(doit.pl), I hope when the user kill my doit.pl, it will
kill the
"system("Doing something take a long time");" process as well, I
really don't want leave the process behind.

Is that anywhere I can find code example doing such thing?

Thanks a lot,
Mav




lee <> wrote in message news:<>...
> Mav wrote:
>
> > I am trying to lanuch a command on my perl script using system call,
> > I wonder is that a way when someone hit Ctrl-Y, it will kill my
> > script,and also kill that system call process as well.

>
> Yes.
>
> When you launch the process, note its process ID.
>
> Then have your script "trap" the control character in question,
> and when that character is received, call the system 'kill'
> command
> on the previously noted PID, as described by someone else on
> this thread.
>
> See, for example, perldoc -q signal:
>
> Found in .... pod/perlfaq8 :
> How do I trap control characters/signals?
>
> $Interrupted = 0; # to ensure it has a value
> $SIG{INT} = sub {
> $Interrupted++;
> syswrite(STDERR, "ouch\n", 5);
> }
>
>
> Lee Goddard

 
Reply With Quote
 
Mothra
Guest
Posts: n/a
 
      06-15-2004
Mav wrote:

> The script is running on the PC.
> Once I launch the "system("Doing something take a long time");" from
> my perl script(doit.pl), I hope when the user kill my doit.pl, it will
> kill the
> "system("Doing something take a long time");" process as well, I
> really don't want leave the process behind.
>
> Is that anywhere I can find code example doing such thing?
>

Try Chapter 16 of "Perl Cookbook" published by O'Reilly - there's loads
of examples in there.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Kill an OS process from script (perhaps unix specific) chengiz@my-deja.com Python 1 04-19-2008 05:49 PM
Kill Thread Within Java.exe Process John A. Bailo Java 3 08-03-2007 06:11 AM
kill the ssh process called by the system command priya Perl Misc 2 01-23-2006 04:40 AM
Bava's KILL BABY KILL widescreen drsd2kill DVD Video 0 11-27-2004 12:04 AM
how to kill a process initiated by system() Howard Perl Misc 4 10-27-2004 05:38 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57