-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsvn.cmds.parent.pl
More file actions
executable file
·108 lines (87 loc) · 2.33 KB
/
svn.cmds.parent.pl
File metadata and controls
executable file
·108 lines (87 loc) · 2.33 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/perl -I ./thirds -w
# author: lilong'en(lilongen@163.com)
#
# exist reason:
# use this process as the fork parent, to minimize memory requirement
#
use strict;
use English;
use Data::Dumper;
use IPC::SysV qw(IPC_PRIVATE S_IRUSR S_IWUSR IPC_CREAT);
use IPC::Semaphore;
sub main();
sub initGV();
sub ifAllChildProcessFinished();
sub showChildProcessesStatus();
sub logInfo($);
my $__DEBUG = 0;
chdir($ARGV[0]);
my $GV = {};
main();
sub initGV() {
$GV->{DfSliceInfo} = {};
$GV->{DfSliceInfo}->{DfCmdsCnt} = $ARGV[1];
$GV->{DfSliceInfo}->{DfCmdsSliceCnt} = $ARGV[2];
$GV->{DfSliceInfo}->{SliceCmdsCnt} = $ARGV[3];
$GV->{DfSliceInfo}->{uid} = $ARGV[4];
$GV->{DfSliceInfo}->{upw} = $ARGV[5];
$GV->{DfCmdsShTpl} = "__ccv_df_slice_%d_%d.sh";
$GV->{DfSliceOutTpl} = "__ccv_df_slice_out_%d_%d";
}
sub main() {
initGV();
$GV->{dfSemaphore} = IPC::Semaphore->new(IPC_PRIVATE, $GV->{DfSliceInfo}->{DfCmdsSliceCnt}, S_IRUSR | S_IWUSR | IPC_CREAT);
#
# smaphore value
# 0: initial
# 1: process started
# 2: process finished
#
$GV->{dfSemaphore}->setall((0) x $GV->{DfSliceInfo}->{DfCmdsSliceCnt});
for (my $i = 0; $i < $GV->{DfSliceInfo}->{DfCmdsSliceCnt}; $i++) {
my $sh = sprintf($GV->{DfCmdsShTpl}, $GV->{DfSliceInfo}->{DfCmdsSliceCnt}, $i);
my $pid = fork();
if (defined($pid)) {
if ($pid == 0) {#child process
$GV->{dfSemaphore}->setval($i, 1);
#system("bash $sh \"$GV->{DfSliceInfo}->{uid}\" $GV->{DfSliceInfo}->{upw}");
system("bash $sh");
$GV->{dfSemaphore}->setval($i, 2);
exit 0;
} else {#parent process
logInfo("new child process pid: $pid");
next;
}
} else {
#create cloned progress failed
}
}
while(1) {
if ($__DEBUG) {
showChildProcessesStatus();
}
if (ifAllChildProcessFinished()) {
$GV->{dfSemaphore}->remove();
last;
}
sleep(5);
}
logInfo "all child process finished!";
}
sub showChildProcessesStatus() {
my @semaDf = $GV->{dfSemaphore}->getall();
print Dumper(@semaDf);
}
sub ifAllChildProcessFinished() {
for (my $i = 0; $i < $GV->{DfSliceInfo}->{DfCmdsSliceCnt}; $i++) {
if ($GV->{dfSemaphore}->getval($i) != 2) {
return 0;
}
}
return 1;
}
sub logInfo($) {
if ($__DEBUG) {
print $_[0] . "\n";
}
}