Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
KWSys
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sylvain Joubert
KWSys
Commits
79a6bee6
Commit
79a6bee6
authored
19 years ago
by
Brad King
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Added implementation of process tree killing that runs "ps" to traverse the tree.
parent
88a52953
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ProcessUNIX.c
+43
-2
43 additions, 2 deletions
ProcessUNIX.c
with
43 additions
and
2 deletions
ProcessUNIX.c
+
43
−
2
View file @
79a6bee6
...
@@ -1898,6 +1898,22 @@ static pid_t kwsysProcessFork(kwsysProcess* cp,
...
@@ -1898,6 +1898,22 @@ static pid_t kwsysProcessFork(kwsysProcess* cp,
}
}
}
}
/*--------------------------------------------------------------------------*/
/* For systems without the /proc filesystem we try to obtain process
information by invoking the ps command. Here we define the command
to call on each platform and the corresponding parsing format
string. The parsing format should have two integers to store: the
pid and then the ppid. */
#if defined(__linux__) || defined(__APPLE__)
# define KWSYSPE_PS_COMMAND "ps axo pid,ppid"
# define KWSYSPE_PS_HEADER "%*s %*s\n"
# define KWSYSPE_PS_FORMAT "%d %d\n"
#elif defined(__hpux) && 0
/* Disable until tested. */
# define KWSYSPE_PS_COMMAND "ps -ef"
# define KWSYSPE_PS_HEADER "%*s %*s %*s %*s %*s %*s %*s %*s\n"
# define KWSYSPE_PS_FORMAT "%*s %d %d %*s %*s %*s %*s %*s\n"
#endif
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
static
void
kwsysProcessKill
(
pid_t
process_id
)
static
void
kwsysProcessKill
(
pid_t
process_id
)
{
{
...
@@ -1906,8 +1922,8 @@ static void kwsysProcessKill(pid_t process_id)
...
@@ -1906,8 +1922,8 @@ static void kwsysProcessKill(pid_t process_id)
/* Suspend the process to be sure it will not create more children. */
/* Suspend the process to be sure it will not create more children. */
kill
(
process_id
,
SIGSTOP
);
kill
(
process_id
,
SIGSTOP
);
/* Kill all children if we can find them.
Currently this works only
/* Kill all children if we can find them.
First try using the /proc
on systems that support the proc
filesystem. */
filesystem. */
if
((
procdir
=
opendir
(
"/proc"
))
!=
NULL
)
if
((
procdir
=
opendir
(
"/proc"
))
!=
NULL
)
{
{
#if defined(MAXPATHLEN)
#if defined(MAXPATHLEN)
...
@@ -1962,6 +1978,31 @@ static void kwsysProcessKill(pid_t process_id)
...
@@ -1962,6 +1978,31 @@ static void kwsysProcessKill(pid_t process_id)
}
}
closedir
(
procdir
);
closedir
(
procdir
);
}
}
#if defined(KWSYSPE_PS_COMMAND)
else
{
/* Try running "ps" to get the process information. */
FILE
*
ps
=
popen
(
KWSYSPE_PS_COMMAND
,
"r"
);
/* Make sure the process started and provided a valid header. */
if
(
ps
&&
fscanf
(
ps
,
KWSYSPE_PS_HEADER
)
!=
EOF
)
{
/* Look for processes whose parent is the process being killed. */
int
pid
,
ppid
;
while
(
fscanf
(
ps
,
KWSYSPE_PS_FORMAT
,
&
pid
,
&
ppid
)
==
2
)
{
if
(
ppid
==
process_id
)
{
/* Recursively kill this child aned its children. */
kwsysProcessKill
(
pid
);
}
}
/* We are done with the ps process. */
pclose
(
ps
);
}
}
#endif
/* Kill the process. */
/* Kill the process. */
kill
(
process_id
,
SIGKILL
);
kill
(
process_id
,
SIGKILL
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment