如何在 Perl 脚本中使用 Ctrl-Z
我正在编写一个 Perl 脚本,我需要在脚本上执行 Unix Ctrl+Z.我怎样才能在 Perl 中做到这一点?
I am writing a Perl script and I need to execute Unix Ctrl+Z on the script. How can I do it in Perl ?
谢谢.
在 perl 中,您可以使用 kill 函数向进程发送信号,该函数与执行相同操作的 Unix 命令行工具同名.相当于 Ctrl+Z 正在运行
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
kill -SIGTSTP pid
您需要找出您的 TSTP 信号在您的系统上的数值.你可以通过运行
you need to find out what numeric value your TSTP signal has on your system. You would do this by running
kill -l TSTP
kill -l TSTP
在命令行上.假设这返回 20
on the command line. Let's say this returns 20
然后在您的 Perl 脚本中添加
Then in your Perl script you would add
杀死 20 => $$;
kill 20 => $$;
将发送 TSTP 信号到当前运行的进程 id ($$)
which will send the TSTP signal to the currently running process id ($$)
更新:如 daxim 所述,您可以跳过kill -l"部分并直接提供信号的名称:
Update: as described by daxim, you can skip the 'kill -l' part and provide the name of the signal directly:
kill 'TSTP' => $$;