• Home
  • Raw
  • Download

Lines Matching +full:- +full:- +full:pid

21 # SPDX-License-Identifier: curl
73 # pidfromfile returns the pid stored in the given pidfile. The value
74 # of the returned pid will never be a negative value. It will be zero
75 # on any file related error or if a pid can not be extracted from the
80 my $pid = 0;
82 if(-f $pidfile && -s $pidfile && open(PIDFH, "<$pidfile")) {
83 $pid = 0 + <PIDFH>;
85 $pid = 0 unless($pid > 0);
87 return $pid;
91 # pidexists checks if a process with a given pid exists and is alive.
92 # This will return the positive pid if the process exists and is alive.
93 # This will return the negative pid if the process exists differently.
97 my $pid = $_[0];
99 if($pid > 0) {
101 if ($pid > 65536 && os_is_win()) {
102 $pid -= 65536;
104 my $filter = "PID eq $pid";
105 my $result = `tasklist -fi \"$filter\" 2>nul`;
106 if(index($result, "$pid") != -1) {
107 return -$pid;
114 if(kill(0, $pid)) {
115 return $pid;
123 # pidterm asks the process with a given pid to terminate gracefully.
126 my $pid = $_[0];
128 if($pid > 0) {
130 if ($pid > 65536 && os_is_win()) {
131 $pid -= 65536;
133 my $filter = "PID eq $pid";
134 my $result = `tasklist -fi \"$filter\" 2>nul`;
135 if(index($result, "$pid") != -1) {
136 system("taskkill -fi \"$filter\" >nul 2>&1");
143 kill("TERM", $pid);
148 # pidkill kills the process with a given pid mercilessly and forcefully.
151 my $pid = $_[0];
153 if($pid > 0) {
155 if ($pid > 65536 && os_is_win()) {
156 $pid -= 65536;
158 my $filter = "PID eq $pid";
159 my $result = `tasklist -fi \"$filter\" 2>nul`;
160 if(index($result, "$pid") != -1) {
161 system("taskkill -f -fi \"$filter\" >nul 2>&1");
163 system("tskill $pid >nul 2>&1");
170 kill("KILL", $pid);
175 # pidwait waits for the process with a given pid to be terminated.
178 my $pid = $_[0];
182 if ($pid > 65536 && os_is_win()) {
184 return pidexists($pid)?0:$pid;
186 while(pidexists($pid)) {
189 return $pid;
193 return waitpid($pid, $flags);
197 # processexists checks if a process with the pid stored in the given
199 # error or if a pid can not be extracted from the given file. When a
200 # process with the same pid as the one extracted from the given file
201 # is currently alive this returns that positive pid. Otherwise, when
202 # the process is not alive, will return the negative value of the pid.
208 # fetch pid from pidfile
209 my $pid = pidfromfile($pidfile);
211 if($pid > 0) {
213 if(pidexists($pid)) {
214 return $pid;
218 unlink($pidfile) if($pid == pidfromfile($pidfile));
220 pidwait($pid, &WNOHANG);
222 return -$pid;
229 # killpid attempts to gracefully stop processes in the given pid list
242 # Make 'requested' hold the non-duplicate pids from 'pidlist'.
248 for(my $i = scalar(@requested) - 2; $i >= 0; $i--) {
258 my $pid = $1;
259 if($pid > 0) {
260 if(pidexists($pid)) {
261 print("RUN: Process with pid $pid signalled to die\n")
263 pidterm($pid);
264 push @signalled, $pid;
267 print("RUN: Process with pid $pid already dead\n")
270 pidwait($pid, &WNOHANG);
271 push @reapchild, $pid;
280 while($twentieths--) {
281 for(my $i = scalar(@signalled) - 1; $i >= 0; $i--) {
282 my $pid = $signalled[$i];
283 if(!pidexists($pid)) {
284 print("RUN: Process with pid $pid gracefully died\n")
288 pidwait($pid, &WNOHANG);
289 push @reapchild, $pid;
299 foreach my $pid (@signalled) {
300 if($pid > 0) {
301 print("RUN: Process with pid $pid forced to die with SIGKILL\n")
303 pidkill($pid);
305 pidwait($pid, &WNOHANG);
306 push @reapchild, $pid;
313 foreach my $pid (@reapchild) {
314 if($pid > 0) {
315 pidwait($pid, 0);
328 my $pid;
339 $pid = processexists($pidfile);
340 if($pid > 0) {
341 printf("* kill pid for %s-%s => %d\n", $server,
342 ($proto eq 'ftp')?'ctrl':'filt', $pid) if($verbose);
343 pidkill($pid);
344 pidwait($pid, 0);
346 unlink($pidfile) if(-f $pidfile);
353 $pid = processexists($pidfile);
354 if($pid > 0) {
355 printf("* kill pid for %s-data => %d\n", $server,
356 $pid) if($verbose);
357 pidkill($pid);
358 pidwait($pid, 0);
360 unlink($pidfile) if(-f $pidfile);
394 if(-f $filename) {