1 |
3 |
ahitrov@rambler.ru |
use strict; |
2 |
|
|
|
3 |
|
|
# ���� �������� ������ ����������� ���������� |
4 |
|
|
# �� ��������� ������ |
5 |
|
|
sub activity { |
6 |
|
|
my $MAXIMUM_ACTIVITY = 10; |
7 |
|
|
my $TOPS = `uptime`; |
8 |
|
|
if ($TOPS =~ /load averages: ([\d\.]+), ([\d\.]+), ([\d\.]+)/) |
9 |
|
|
{ |
10 |
|
|
my $CA = $2; |
11 |
|
|
$CA = $1 if ($CA < $1); |
12 |
|
|
if (($CA) > $MAXIMUM_ACTIVITY) |
13 |
|
|
{ |
14 |
|
|
return 0; |
15 |
|
|
} |
16 |
|
|
} |
17 |
|
|
return 1; |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
# ���������� pid'� �������� |
21 |
|
|
sub save_pid { |
22 |
|
|
my $FILE = shift; |
23 |
|
|
open F, ">".$FILE.".pid" || die "�� ���� ������� pid ���� ".$FILE.".pid \n"; |
24 |
|
|
print F $$; |
25 |
|
|
close F || die "�� ���� ������� pid ���� ".$FILE.".pid \n"; |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
|
29 |
|
|
# �������� ����������� ���������� ��������� |
30 |
|
|
# �� ��� ��� ������ |
31 |
|
|
sub check_pid { |
32 |
|
|
my $FILE = shift || __FILE__; |
33 |
|
|
if (-s $FILE.".pid") { |
34 |
|
|
open F, "<".$FILE.".pid" || die "�� ���� ������� pid ���� ".$FILE.".pid \n"; |
35 |
|
|
my $pid = (<F>)[0]; |
36 |
|
|
chomp $pid; |
37 |
|
|
close F || die "�� ���� ������� pid ���� ".$FILE.".pid \n"; |
38 |
|
|
if (kill 0 => $pid) { |
39 |
|
|
warn "��������� ��� �������� -> �����\n"; |
40 |
|
|
exit; |
41 |
|
|
} else { |
42 |
|
|
&save_pid($FILE); |
43 |
|
|
} |
44 |
|
|
} else { |
45 |
|
|
&save_pid($FILE); |
46 |
|
|
} |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
1; |