perl启动后台进程
http://www.cnblogs.com/firetw/
之前写的一个文章,那个马夹不用了。
今天遇到一个perl启动后台进程的问题,就是是在启动命令后面加"&"的进程还是顺序,特做此小实验。
a.pl调度
#!/usr/bin/perl -w use Data::Dumper; my $cmd1="perl b.pl &"; my $cmd2="perl b.pl &"; my @result=`$cmd1`; my @result1=`$cmd2`; #system($cmd1); #system($cmd2); print Dumper(@result),"\n"; print Dumper(@result1),"\n";
这种方式是确实是顺序执行的,但是用system调试是并行的。
b.pl
#!/usr/bin/perl -w print $$." begin ".current(),"\n"; sleep 20; print $$." end ".current(),"\n"; sub current { my ($sec,$min,$hour,$mday,$mon,$year) = localtime(); $year += 1900; $mon ++; ($sec,$min,$hour,$mday,$mon,$year) = format_date($sec,$min,$hour,$mday,$mon,$year); return "$year-$mon-$mday $hour:$min:$sec"; } sub format_date { my(@items) = @_; my $pattern = "[-\/ :]+"; foreach my $item (@items) { $item = (length($item)==1) ? "0$item":$item; } return @items; }