Lines Matching refs:pid
90 # pidfromfile returns the pid stored in the given pidfile. The value
91 # of the returned pid will never be a negative value. It will be zero
92 # on any file related error or if a pid can not be extracted from the
97 my $pid = 0;
100 $pid = 0 + <$pidfh>;
102 $pid = 0 if($pid < 0);
104 return $pid;
108 # pidexists checks if a process with a given pid exists and is alive.
109 # This will return the positive pid if the process exists and is alive.
110 # This will return the negative pid if the process exists differently.
114 my $pid = $_[0];
116 if($pid > 0) {
118 if ($pid > 65536 && os_is_win()) {
119 $pid -= 65536;
121 my $filter = "PID eq $pid";
123 if(index($result, "$pid") != -1) {
124 return -$pid;
131 if(kill(0, $pid)) {
132 return $pid;
140 # pidterm asks the process with a given pid to terminate gracefully.
143 my $pid = $_[0];
145 if($pid > 0) {
147 if ($pid > 65536 && os_is_win()) {
148 $pid -= 65536;
150 my $filter = "PID eq $pid";
152 if(index($result, "$pid") != -1) {
160 kill("TERM", $pid);
165 # pidkill kills the process with a given pid mercilessly and forcefully.
168 my $pid = $_[0];
170 if($pid > 0) {
172 if ($pid > 65536 && os_is_win()) {
173 $pid -= 65536;
175 my $filter = "PID eq $pid";
177 if(index($result, "$pid") != -1) {
180 system("tskill $pid >nul 2>&1");
187 kill("KILL", $pid);
192 # pidwait waits for the process with a given pid to be terminated.
195 my $pid = $_[0];
199 if ($pid > 65536 && os_is_win()) {
201 return pidexists($pid)?0:$pid;
203 while(pidexists($pid)) {
206 return $pid;
210 return waitpid($pid, $flags);
214 # processexists checks if a process with the pid stored in the given
216 # error or if a pid can not be extracted from the given file. When a
217 # process with the same pid as the one extracted from the given file
218 # is currently alive this returns that positive pid. Otherwise, when
219 # the process is not alive, will return the negative value of the pid.
225 # fetch pid from pidfile
226 my $pid = pidfromfile($pidfile);
228 if($pid > 0) {
230 if(pidexists($pid)) {
231 return $pid;
235 unlink($pidfile) if($pid == pidfromfile($pidfile));
237 pidwait($pid, &WNOHANG);
239 return -$pid;
246 # killpid attempts to gracefully stop processes in the given pid list
275 my $pid = $1;
276 if($pid > 0) {
277 if(pidexists($pid)) {
278 print("RUN: Process with pid $pid signalled to die\n")
280 pidterm($pid);
281 push @signalled, $pid;
284 print("RUN: Process with pid $pid already dead\n")
287 pidwait($pid, &WNOHANG);
288 push @reapchild, $pid;
299 my $pid = $signalled[$i];
300 if(!pidexists($pid)) {
301 print("RUN: Process with pid $pid gracefully died\n")
305 pidwait($pid, &WNOHANG);
306 push @reapchild, $pid;
316 foreach my $pid (@signalled) {
317 if($pid > 0) {
318 print("RUN: Process with pid $pid forced to die with SIGKILL\n")
320 pidkill($pid);
322 pidwait($pid, &WNOHANG);
323 push @reapchild, $pid;
330 foreach my $pid (@reapchild) {
331 if($pid > 0) {
332 pidwait($pid, 0);
345 my $pid;
356 $pid = processexists($pidfile);
357 if($pid > 0) {
358 printf("* kill pid for %s-%s => %d\n", $server,
359 ($proto eq 'ftp')?'ctrl':'filt', $pid) if($verbose);
360 pidkill($pid);
361 pidwait($pid, 0);
370 $pid = processexists($pidfile);
371 if($pid > 0) {
372 printf("* kill pid for %s-data => %d\n", $server,
373 $pid) if($verbose);
374 pidkill($pid);
375 pidwait($pid, 0);