开发者

How to Ctrl-Z in Perl script

开发者 https://www.devze.com 2023-01-09 19:18 出处:网络
I am writing a Perl script and I need to execute Unix Ctrl+Z on the 开发者_如何学Pythonscript. How can I do it in Perl ?

I am writing a Perl script and I need to execute Unix Ctrl+Z on the 开发者_如何学Pythonscript. How can I do it in Perl ?

thanks.


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' => $$;


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..

0

精彩评论

暂无评论...
验证码 换一张
取 消