37,719
社区成员
发帖
与我相关
我的任务
分享
use warnings;
use strict;
my($pid);
$| = 1;
if($pid=fork())
{
print("$pid \n");
sleep(1);
while(1)
{
if (isOvertime())
{
kill('STOP',$pid);
print("Sorry,you are overtime .\n");
exit();
}
else
{
if(wait())
{
print("OK , now i can go .\n");
exit();
}
}
}
}
elsif(defined($pid))
{
sleep(30);
print("i am ok! \n");
exit();
}
else
{
print("error \n");
}
use warnings;
use strict;
use POSIX 'WNOHANG';
$SIG{ STOP } = \&stop;
my($pid);
$| = 1;
if($pid=fork())
{
print("$pid \n");
sleep(1);
while(1)
{
if (isOvertime())
{
kill('STOP',$pid);
print("Sorry,you are overtime .\n");
exit();
}
else
{
if(waitpid(-1,WNOHANG))
{
print("OK , now i can go .\n");
exit();
}
}
}
}
elsif(defined($pid))
{
my $parent=getppid();
print ("$parent \n");
sleep(10);
print("i am ok! \n");
exit();
}
else
{
print("error \n");
}