tags:

views:

128

answers:

3

Hi,

I am writing a Perl script and I need to execute Unix Ctrl-Z on the script. How can I do it in Perl ?

thanks.

A: 

In bash ctrl-z stops the current job and puts it in background with %JobId you can return to this job. I'm not sure what you mean since I thought ctrl-z is caught by bash..

Nils
I want the script to send the bash to put a specific job in the background.
guy ergas
A: 

Are you trying to send SIGHUP to any process from the script? If yes this page will help you Raghu

Raghuram
why there is down vote for this ? whats the issue with this?
Raghuram
Raghuram: HUP is not the right signal
ysth
+3  A: 

From perl you can send signals to processes with the function kill, which has the same name as the Unix command line tool that does the same thing. The equivalent to Ctrl-Z is running

kill -SIGTSTP pid

you need to find out what numeric value your TSTP signal has on your system. You would do this by running

kill -l TSTP

on the command line. Let's say this returns 20

Then in your Perl script you would add

kill 20 => $$;

which will send the TSTP signal to the currently running process id ($$)

Update: as described by daxim, you can skip the 'kill -l' part and provide the name of the signal directly:

kill 'TSTP' => $$;
ivancho
Too complicated. Just `kill 'TSTP' …`, `kill 'HUP' …` etc. See http://p3rl.org/ipc
daxim
thank you a lot :)
guy ergas
@daxim Thank you, you are right about the syntax, though I really wouldn't point perlipc as gentle help for people who don't know about signals
ivancho