system 函数:
在Perl中,启动子进程最简单的方法是用system 函数,例如要调用Unix的date命令,
system "date";
这会创建一个子进程来运行date命令
[root@jhoa 20150304]# cat a1.pl
#!/usr/bin/perl
if (system 'date'){print "$!--1------
";}else
{print "$!--2------
";}
[root@jhoa 20150304]# perl a1.pl
Wed Mar 4 15:36:32 CST 2015
--2------
system调用后,返回值为shell的返回值 0为真 所以这里是反的
[root@jhoa 20150304]# cat a2.pl
system 'sleep 100';
[oracle@jhoa perl]$ ps -ef | grep 15653
root 15653 6886 0 16:05 pts/0 00:00:00 perl a2.pl
root 15654 15653 0 16:05 pts/0 00:00:00 sleep 100
oracle 15658 7246 0 16:06 pts/1 00:00:00 grep 15653
system 会创建一个新的子进程
exec 函数会导致perl进程自己去执行任务
[oracle@jhoa perl]$ ps -ef | grep perl
oracle 15700 7246 0 16:08 pts/1 00:00:00 grep perl
[oracle@jhoa perl]$ ps -ef | grep sleep
root 15687 6886 0 16:07 pts/0 00:00:00 sleep 100
oracle 15702 7246 0 16:08 pts/1 00:00:00 grep sleep
发送及接收信号:
[root@jhoa 20150304]# ps -ef | grep perl
oracle 15819 7290 0 17:09 pts/2 00:00:00 perl client.pl
root 15827 6886 0 17:09 pts/0 00:00:00 grep perl
[root@jhoa 20150304]# cat kill.pl
kill 2,15819 or die "Cannot signal 15819 with SIGINT:$!";
[root@jhoa 20150304]# perl kill.pl
[root@jhoa 20150304]# ps -ef | grep perl
root 15878 6886 0 17:11 pts/0 00:00:00 grep perl