Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option -g: kill all processes within a process group #247

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions MANPAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ When earlyoom is run through its default systemd service, the `-p` switch doesn'
#### -n
Enable notifications via d-bus.

#### -g
Kill all processes that are in the same process group as the one with excessive memory usage.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please give a short description when a user should enable this flag

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Added a more detailed description.


#### \-\-prefer REGEX
prefer killing processes matching REGEX (adds 300 to oom_score)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ Usage: ./earlyoom [OPTION]...
-i user-space oom killer should ignore positive
oom_score_adj values
-n enable d-bus notifications
-g kill all processes within a process group
-d enable debugging messages
-v print version information and exit
-r INTERVAL memory report interval in seconds (default 1), set
Expand Down
3 changes: 3 additions & 0 deletions kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ int kill_wait(const poll_loop_args_t* args, pid_t pid, int sig)
}
meminfo_t m = { 0 };
const unsigned poll_ms = 100;
if (args->kill_process_group) {
pid = -getpgid(pid);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error handling, please! getpgid() can fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I'm not sure how the error code in fatal() is chosen so for now I just randomly picked 7.

}
int res = kill(pid, sig);
if (res != 0) {
return res;
Expand Down
2 changes: 2 additions & 0 deletions kill.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ typedef struct {
bool ignore_oom_score_adj;
/* send d-bus notifications? */
bool notify;
/* kill all processes within a process group */
bool kill_process_group;
/* prefer/avoid killing these processes. NULL = no-op. */
regex_t* prefer_regex;
regex_t* avoid_regex;
Expand Down
6 changes: 5 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int main(int argc, char* argv[])
meminfo_t m = parse_meminfo();

int c;
const char* short_opt = "m:s:M:S:kinN:dvr:ph";
const char* short_opt = "m:s:M:S:kingN:dvr:ph";
struct option long_opt[] = {
{ "prefer", required_argument, NULL, LONG_OPT_PREFER },
{ "avoid", required_argument, NULL, LONG_OPT_AVOID },
Expand Down Expand Up @@ -173,6 +173,9 @@ int main(int argc, char* argv[])
args.notify = true;
fprintf(stderr, "Notifying through D-Bus\n");
break;
case 'g':
args.kill_process_group = true;
break;
case 'N':
args.notify = true;
fprintf(stderr, "Notifying through D-Bus, argument '%s' ignored for compatability\n", optarg);
Expand Down Expand Up @@ -220,6 +223,7 @@ int main(int argc, char* argv[])
" -i user-space oom killer should ignore positive\n"
" oom_score_adj values\n"
" -n enable d-bus notifications\n"
" -g kill all processes within a process group\n"
" -d enable debugging messages\n"
" -v print version information and exit\n"
" -r INTERVAL memory report interval in seconds (default 1), set\n"
Expand Down