Lines Matching full:pid
71 # pidfromfile returns the pid stored in the given pidfile. The value
72 # of the returned pid will never be a negative value. It will be zero
73 # on any file related error or if a pid can not be extracted from the
78 my $pid = 0;
81 $pid = 0 + <PIDFH>;
83 $pid = 0 unless($pid > 0);
85 return $pid;
89 # pidexists checks if a process with a given pid exists and is alive.
90 # This will return the positive pid if the process exists and is alive.
91 # This will return the negative pid if the process exists differently.
95 my $pid = $_[0];
97 if($pid > 0) {
99 if ($pid > 65536 && os_is_win()) {
100 $pid -= 65536;
102 my $filter = "PID eq $pid";
104 if(index($result, "$pid") != -1) {
105 return -$pid;
112 if(kill(0, $pid)) {
113 return $pid;
121 # pidterm asks the process with a given pid to terminate gracefully.
124 my $pid = $_[0];
126 if($pid > 0) {
128 if ($pid > 65536 && os_is_win()) {
129 $pid -= 65536;
131 my $filter = "PID eq $pid";
133 if(index($result, "$pid") != -1) {
141 kill("TERM", $pid);
146 # pidkill kills the process with a given pid mercilessly and forcefully.
149 my $pid = $_[0];
151 if($pid > 0) {
153 if ($pid > 65536 && os_is_win()) {
154 $pid -= 65536;
156 my $filter = "PID eq $pid";
158 if(index($result, "$pid") != -1) {
161 system("tskill $pid >nul 2>&1");
168 kill("KILL", $pid);
173 # pidwait waits for the process with a given pid to be terminated.
176 my $pid = $_[0];
180 if ($pid > 65536 && os_is_win()) {
182 return pidexists($pid)?0:$pid;
184 while(pidexists($pid)) {
187 return $pid;
191 return waitpid($pid, $flags);
195 # processexists checks if a process with the pid stored in the given
197 # error or if a pid can not be extracted from the given file. When a
198 # process with the same pid as the one extracted from the given file
199 # is currently alive this returns that positive pid. Otherwise, when
200 # the process is not alive, will return the negative value of the pid.
206 # fetch pid from pidfile
207 my $pid = pidfromfile($pidfile);
209 if($pid > 0) {
211 if(pidexists($pid)) {
212 return $pid;
216 unlink($pidfile) if($pid == pidfromfile($pidfile));
218 pidwait($pid, &WNOHANG);
220 return -$pid;
227 # killpid attempts to gracefully stop processes in the given pid list
256 my $pid = $1;
257 if($pid > 0) {
258 if(pidexists($pid)) {
259 print("RUN: Process with pid $pid signalled to die\n")
261 pidterm($pid);
262 push @signalled, $pid;
265 print("RUN: Process with pid $pid already dead\n")
268 pidwait($pid, &WNOHANG);
269 push @reapchild, $pid;
280 my $pid = $signalled[$i];
281 if(!pidexists($pid)) {
282 print("RUN: Process with pid $pid gracefully died\n")
286 pidwait($pid, &WNOHANG);
287 push @reapchild, $pid;
297 foreach my $pid (@signalled) {
298 if($pid > 0) {
299 print("RUN: Process with pid $pid forced to die with SIGKILL\n")
301 pidkill($pid);
303 pidwait($pid, &WNOHANG);
304 push @reapchild, $pid;
311 foreach my $pid (@reapchild) {
312 if($pid > 0) {
313 pidwait($pid, 0);
326 my $pid;
337 $pid = processexists($pidfile);
338 if($pid > 0) {
339 printf("* kill pid for %s-%s => %d\n", $server,
340 ($proto eq 'ftp')?'ctrl':'filt', $pid) if($verbose);
341 pidkill($pid);
342 pidwait($pid, 0);
351 $pid = processexists($pidfile);
352 if($pid > 0) {
353 printf("* kill pid for %s-data => %d\n", $server,
354 $pid) if($verbose);
355 pidkill($pid);
356 pidwait($pid, 0);