FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bazel-java/src/main/tools/process-tools-linux.cc at master · codemod/bazel-java · GitHub
codemod
bazel-java
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
bazel-java
/
src
/
main
/
tools
/
process-tools-linux.cc
Copy path
More file actions
More file actions
Latest commit
History
History
History
55 lines (49 loc) · 1.63 KB
Breadcrumbs
bazel-java
/
src
/
main
/
tools
/
process-tools-linux.cc
Copy path
File metadata and controls
55 lines (49 loc) · 1.63 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
Copyright 2019 The Bazel Authors. All rights reserved.
//
//
Licensed under the Apache License, Version 2.0 (the "License");
//
you may not use this file except in compliance with the License.
//
You may obtain a copy of the License at
//
//
http://www.apache.org/licenses/LICENSE-2.0
//
//
Unless required by applicable law or agreed to in writing, software
//
distributed under the License is distributed on an "AS IS" BASIS,
//
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
See the License for the specific language governing permissions and
//
limitations under the License.
#
include
<
errno.h
>
#
include
<
signal.h
>
#
include
<
stdio.h
>
#
include
<
sys/types.h
>
#
include
<
sys/wait.h
>
#
include
<
unistd.h
>
#
include
"
src/main/tools/process-tools.h
"
int
TerminateAndWaitForAll
(
pid_t
pid) {
kill
(-pid,
SIGKILL
);
int
res;
while
((res =
waitpid
(-
1
,
nullptr
,
WNOHANG
)) >
0
) {
//
Got one child; try again.
}
if
(res == -
1
) {
//
The fast path got all children, so there is nothing else to do.
return
0
;
}
//
Cope with children that may have escaped the process group or that
//
did not exit quickly enough.
FILE
*f =
fopen
(
"
/proc/thread-self/children
"
,
"
r
"
);
if
(f ==
nullptr
) {
//
Oh oh. This feature may be disabled, in which case there is
//
nothing we can do. Stop early and let any stale children be
//
reparented to init.
return
0
;
}
setbuf
(f,
nullptr
);
int
child_pid;
while
((
waitpid
(-
1
,
nullptr
,
WNOHANG
) != -
1
|| errno !=
ECHILD
) &&
(
rewind
(f),
1
==
fscanf
(f,
"
%d
"
, &child_pid))) {
kill
(child_pid,
SIGKILL
);
usleep
(
100
);
}
fclose
(f);
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL