我有一个执行如下Shell命令的Perl脚本
system("command");
我需要将该命令的执行挂起一定的时间,然后再从脚本本身重新开始执行。我尝试执行以下操作
#!/usr/bin/perl
$pid = fork();
if( $pid == 0 ) {
print "This is child process\n";
exec('command') or die($!);
print "Child process is exiting\n";
exit 0;
}
print "This is parent process and child ID is $pid\n";
kill 'TSTP',$pid;
sleep 60;
kill 'CONT',$pid;
while (wait() != -1) {}
print "Parent process is exiting\n";
exit 0;
但这是我得到的输出
This is child process
Output of command
This is parent process and child ID is 15606
Parent process is exiting
在执行finsh命令后,父进程会暂停子进程,这不是我所需要的。 我也检查了这个问题的答案
但我不确定如何使用
kill 'TSTP' => $$;
暂停正在运行的命令,然后再次恢复。
谢谢。