如何在 Perl 脚本中使用 Ctrl-Z [英] How to Ctrl-Z in Perl script

查看:71
本文介绍了如何在 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' => $$;

这篇关于如何在 Perl 脚本中使用 Ctrl-Z的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆