Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Kill a script

Status
Not open for further replies.

jriggs420

Programmer
Sep 30, 2005
116
US
I'm looking for a way to kill a script on user input from the keyboard. I was originally trying to use a while loop, but that didn't really accomplish what I wanted (at least the the way I did it). Some folks over on the CB at perlmonks recommended using perl's fork function. I read the documentation on it, and couldn't make heads or tails of it. I'm not having to much luck finding useful examples on the web either, could someone at least give me a place to start here? TIA-

Joe

Because a thing seems difficult for you, do not think it impossible for anyone to accomplish.
Marcus Aurelius
 
A semaphore

[program to be killed]
... init ...
while (exists (semaphore)) {
...
}
exit;
[/program]
[program to kill]
if (want to kill program(prog)) {
prog.semaphore.yoink
}
[/program]
yoink could be a function to delete a dummy file, increment a variable in shared memory, I'm sure you get the jist ...

HTH

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Thanks for the reply Paul. I'm not sure I completely follow the example you've given. I think I wasn't specific enough in the OP. I'm basically looking for an alternative to 'ctrl+y' (linux), or ctrl+alt+del (windows). Killing the script in this manner seems sloppy/inefficient/dangerous???, so I was wanting to add something to the actual script (program, whatever) itself to kill it(self) cleanly...wow, that sounds bad, but I hope you get the idea-

Because a thing seems difficult for you, do not think it impossible for anyone to accomplish.
Marcus Aurelius
 
Term::Readkey on should be what you're after

If you read the terminal at the end, or start, of each iteration, you should be golden ...

--Paul

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
are you wanting only certain user input to kill a script, or do you mean exit a script? Can't the user enter CNTRL C or whatver is appropriate to trigger a signal (INT)?
 
Ctrl C will stop wherever the control is at the point of execution, had a feeling that the OP wanted it to exit gracefully ...

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Sorry, looking back, exit would have been the better choice of words. I was learning all about forking, so I had parents killing children on my mind when I wrote it. Still it's not too clear in my mind the difference between 'killing' a script and 'exit' they look to have the same net effect, no? And, yes any input from the keyboard would be fine, I was really looking for a place to start since I was coming up with nothing on the net, thanks again-

Because a thing seems difficult for you, do not think it impossible for anyone to accomplish.
Marcus Aurelius
 
you can always do something as simple as

Code:
chomp (my $stdin = <STDIN>);
exit if lc($stdin) eq 'abort';

where 'abort' is the term to exit the script. and lc() is just to make the match case insensitive;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top