Skip to content
Snippets Groups Projects
Commit a7ccae79 authored by Petr Baudis's avatar Petr Baudis
Browse files

stop -> kill, pointed out by mj to be less confusing

parent 0d76062b
Branches
No related tags found
No related merge requests found
...@@ -10,8 +10,8 @@ Usage ...@@ -10,8 +10,8 @@ Usage
compctl --usage compctl --usage
compctl --limitmem MAXMEM compctl --limitmem MAXMEM
compctl --list compctl --list
compctl --stop PGRP compctl --kill PGRP
compctl --stopall compctl --killall
Arguments for running computations: Arguments for running computations:
--run COMMAND run a new computation on foreground --run COMMAND run a new computation on foreground
...@@ -22,8 +22,8 @@ Arguments for controlling computations: ...@@ -22,8 +22,8 @@ Arguments for controlling computations:
--usage show resource usage of all running computations --usage show resource usage of all running computations
--limitmem MAXMEM set the maximum memory consumed by all computations [MiB] --limitmem MAXMEM set the maximum memory consumed by all computations [MiB]
--list list all running computations --list list all running computations
--stop PGRP stop a given computation (number as listed in --list) --kill PGRP kill a given computation (number as listed in --list)
--stopall stop all running computations --killall kill all running computations
Other options: Other options:
--help help message --help help message
...@@ -44,4 +44,4 @@ Examples ...@@ -44,4 +44,4 @@ Examples
compctl --screen autotest-screen 5 compctl --screen autotest-screen 5
compctl --limitmem 4096 compctl --limitmem 4096
compctl --stop 27134 compctl --kill 27134
...@@ -34,10 +34,10 @@ compctl \- Computations under control ...@@ -34,10 +34,10 @@ compctl \- Computations under control
.RI --list .RI --list
.br .br
.B compctl .B compctl
.RI --stop " PGRP " .RI --kill " PGRP "
.br .br
.B compctl .B compctl
.RI --stopall .RI --killall
.br .br
.SH DESCRIPTION .SH DESCRIPTION
\fBComputations under control\fP will run a specificed program as \fBComputations under control\fP will run a specificed program as
...@@ -56,7 +56,7 @@ compctl --screen autotest-screen 5 ...@@ -56,7 +56,7 @@ compctl --screen autotest-screen 5
.br .br
compctl --limitmem 4096 compctl --limitmem 4096
.br .br
compctl --stop 27134 compctl --kill 27134
.br .br
.SH AUTHOR .SH AUTHOR
\fBcompctl\fP was written by Petr Baudis <pasky@ucw.cz>. \fBcompctl\fP was written by Petr Baudis <pasky@ucw.cz>.
...@@ -130,9 +130,9 @@ screen(int argc, char *argv[]) ...@@ -130,9 +130,9 @@ screen(int argc, char *argv[])
} }
void void
stop(pid_t pid) kill_task(pid_t pid)
{ {
char cmd[256]; snprintf(cmd, sizeof(cmd), "stop %d", pid); char cmd[256]; snprintf(cmd, sizeof(cmd), "kill %d", pid);
char *line = daemon_chat(cmd); char *line = daemon_chat(cmd);
if (line[0] != '1') { if (line[0] != '1') {
fprintf(stderr, "%s\n", *line ? line : "unexpected hangup"); fprintf(stderr, "%s\n", *line ? line : "unexpected hangup");
...@@ -142,9 +142,9 @@ stop(pid_t pid) ...@@ -142,9 +142,9 @@ stop(pid_t pid)
} }
void void
stop_all(void) kill_all(void)
{ {
char *line = daemon_chat("stopall"); char *line = daemon_chat("killall");
if (line[0] != '1') { if (line[0] != '1') {
fprintf(stderr, "%s\n", *line ? line : "unexpected hangup"); fprintf(stderr, "%s\n", *line ? line : "unexpected hangup");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -164,7 +164,7 @@ limit_mem(size_t limit) ...@@ -164,7 +164,7 @@ limit_mem(size_t limit)
fprintf(stderr, "%s\n", *line ? line : "unexpected hangup"); fprintf(stderr, "%s\n", *line ? line : "unexpected hangup");
if (line[0] == '0') { if (line[0] == '0') {
fprintf(stderr, "Most likely, the computations are already using too much memory.\n" fprintf(stderr, "Most likely, the computations are already using too much memory.\n"
"Consider stopping some of them first.\n"); "Consider killing some of them first.\n");
} }
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
...@@ -224,15 +224,15 @@ main(int argc, char *argv[]) ...@@ -224,15 +224,15 @@ main(int argc, char *argv[])
} else if (!strcmp(cmd, "--list")) { } else if (!strcmp(cmd, "--list")) {
list(); list();
} else if (!strcmp(cmd, "--stop")) { } else if (!strcmp(cmd, "--kill")) {
if (argc <= optind) { if (argc <= optind) {
fputs("missing argument for --stop\n", stderr); fputs("missing argument for --kill\n", stderr);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
stop(atoi(argv[optind++])); kill_task(atoi(argv[optind++]));
} else if (!strcmp(cmd, "--stopall")) { } else if (!strcmp(cmd, "--killall")) {
stop_all(); kill_all();
} else if (!strcmp(cmd, "--limitmem")) { } else if (!strcmp(cmd, "--limitmem")) {
if (argc <= optind) { if (argc <= optind) {
......
...@@ -205,12 +205,12 @@ sockerror: ...@@ -205,12 +205,12 @@ sockerror:
else else
mprintf(fd, "1 blessed"); mprintf(fd, "1 blessed");
} else if (begins_with("stop ", line)) { } else if (begins_with("kill ", line)) {
pid_t pid = atoi(line + strlen("stop ")); pid_t pid = atoi(line + strlen("kill "));
/* Sanity check. */ /* Sanity check. */
if (pid < 10) { if (pid < 10) {
syslog(LOG_WARNING, "stop: invalid pid (%d)", pid); syslog(LOG_WARNING, "kill: invalid pid (%d)", pid);
mprintf(fd, "0 invalid pid"); mprintf(fd, "0 invalid pid");
close(fd); close(fd);
continue; continue;
...@@ -221,12 +221,12 @@ sockerror: ...@@ -221,12 +221,12 @@ sockerror:
continue; continue;
} }
syslog(LOG_INFO, "stopping process %d (request by pid %d uid %d)", pid, cred->pid, cred->uid); syslog(LOG_INFO, "killing process %d (request by pid %d uid %d)", pid, cred->pid, cred->uid);
kill(pid, SIGTERM); kill(pid, SIGTERM);
/* TODO: Grace period and then kill with SIGKILL. */ /* TODO: Grace period and then kill with SIGKILL. */
mprintf(fd, "1 task stopped"); mprintf(fd, "1 task killed");
} else if (!strcmp("stopall", line)) { } else if (!strcmp("killall", line)) {
pid_t *tasks; pid_t *tasks;
int tasks_n = cgroup_task_list(chier, cgroup, &tasks); int tasks_n = cgroup_task_list(chier, cgroup, &tasks);
if (tasks_n < 0) { if (tasks_n < 0) {
...@@ -235,11 +235,11 @@ sockerror: ...@@ -235,11 +235,11 @@ sockerror:
continue; continue;
} }
for (int i = 0; i < tasks_n; i++) { for (int i = 0; i < tasks_n; i++) {
syslog(LOG_INFO, "stopping process %d (mass request by pid %d uid %d)", tasks[i], cred->pid, cred->uid); syslog(LOG_INFO, "killing process %d (mass request by pid %d uid %d)", tasks[i], cred->pid, cred->uid);
kill(tasks[i], SIGTERM); kill(tasks[i], SIGTERM);
} }
/* TODO: Grace period and then kill with SIGKILL. */ /* TODO: Grace period and then kill with SIGKILL. */
mprintf(fd, "1 %d tasks stopped", tasks_n); mprintf(fd, "1 %d tasks killed", tasks_n);
free(tasks); free(tasks);
} else if (begins_with("limitmem ", line)) { } else if (begins_with("limitmem ", line)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment