How to Ctrl-Z in Perl script

ⅰ亾dé卋堺 提交于 2021-02-08 11:15:24

问题


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.


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/3394391/how-to-ctrl-z-in-perl-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!