-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpid.pl
More file actions
36 lines (35 loc) · 978 Bytes
/
pid.pl
File metadata and controls
36 lines (35 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/perl -w
print "My process is: $$\n";
$PIDFILE = "/var/run/backup.pid";
if (-f $PIDFILE)
{
open(PIDFILE);
$pid=<PIDFILE>;
close(PIDFILE);
chomp $pid;
print "backup.pid content: $pid\n";
while($pid > 0)
{
open(PIDFILE);
$pid=<PIDFILE>;
close(PIDFILE);
chomp $pid;
print "PID: $pid\n";
`ps -p $pid > /dev/null 2>&1`;
$exit = $?;
print "exit: $exit\n";
if($exit == 0)
{
print "sleeping...";
sleep 30;
}
else
{
print "Process $pid is gone\n";
$pid = 0;
}
}
}
open(RUN, ">$PIDFILE") or die "Can't open $PIDFILE for write: $!\n";
print RUN $$;
close RUN;