Adding -k, kill job (SIGTERM to process group).
Equivalent to "kill -- -`ts -p`".
--- a/Changelog Sat Dec 19 21:29:43 2015 +0100
+++ b/Changelog Sat Mar 19 11:14:18 2016 +0100
@@ -11,8 +11,8 @@
Future:
- Use a better system than mkstemp() for finding output files, so we can add
.gz to the gzipped outputs.
-v0.7.5:
- - Fixing a bug that made the sever crash in MacOSX: strdup() related.
+v0.7.6:
+ - Add -k (send SIGTERM to process group). Replacement for "kill -- -`ts -p`".
v0.7.4:
- Fixing a bug about dangling processes, in case of using "ts -r".
v0.7.3:
--- a/client.c Sat Dec 19 21:29:43 2015 +0100
+++ b/client.c Sat Mar 19 11:14:18 2016 +0100
@@ -11,6 +11,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
+#include <signal.h>
#include "main.h"
static void c_end_of_job(const struct Result *res);
@@ -414,6 +415,22 @@
printf("%i\n", pid);
}
+void c_kill_job()
+{
+ int pid = 0;
+ /* This will exit if there is any error */
+ get_output_file(&pid);
+
+ if (pid == -1 || pid == 0)
+ {
+ fprintf(stderr, "Error: strange PID received: %i\n", pid);
+ exit(-1);
+ }
+
+ /* Send SIGTERM to the process group, as pid is for process group */
+ kill(-pid, SIGTERM);
+}
+
void c_remove_job()
{
struct msg m;
--- a/main.c Sat Dec 19 21:29:43 2015 +0100
+++ b/main.c Sat Mar 19 11:14:18 2016 +0100
@@ -84,7 +84,7 @@
/* Parse options */
while(1) {
- c = getopt(argc, argv, ":VhKgClnfmBEr:t:c:o:p:w:u:s:U:i:N:L:dS:D:");
+ c = getopt(argc, argv, ":VhKgClnfmBEr:t:c:o:p:w:k:u:s:U:i:N:L:dS:D:");
if (c == -1)
break;
@@ -95,6 +95,10 @@
command_line.request = c_KILL_SERVER;
command_line.should_go_background = 0;
break;
+ case 'k':
+ command_line.request = c_KILL_JOB;
+ command_line.jobid = atoi(optarg);
+ break;
case 'l':
command_line.request = c_LIST;
break;
@@ -246,6 +250,10 @@
command_line.jobid = -1; /* This means the 'last'
added job */
break;
+ case 'k':
+ command_line.request = c_KILL_JOB;
+ command_line.jobid = -1; /* This means the 'last' job */
+ break;
case 'S':
command_line.request = c_GET_MAX_SLOTS;
break;
@@ -351,6 +359,7 @@
printf(" -s [id] show the job state. Of the last added, if not specified.\n");
printf(" -r [id] remove a job. The last added, if not specified.\n");
printf(" -w [id] wait for a job. The last added, if not specified.\n");
+ printf(" -k [id] send SIGTERM to the job process group. The last run, if not specified.\n");
printf(" -u [id] put that job first. The last added, if not specified.\n");
printf(" -U <id-id> swap two jobs in the queue.\n");
printf(" -B in case of full queue on the server, quit (2) instead of waiting.\n");
@@ -479,6 +488,11 @@
error("The command %i needs the server", command_line.request);
c_show_pid();
break;
+ case c_KILL_JOB:
+ if (!command_line.need_server)
+ error("The command %i needs the server", command_line.request);
+ c_kill_job();
+ break;
case c_INFO:
if (!command_line.need_server)
error("The command %i needs the server", command_line.request);
--- a/main.h Sat Dec 19 21:29:43 2015 +0100
+++ b/main.h Sat Mar 19 11:14:18 2016 +0100
@@ -63,7 +63,8 @@
c_SWAP_JOBS,
c_INFO,
c_SET_MAX_SLOTS,
- c_GET_MAX_SLOTS
+ c_GET_MAX_SLOTS,
+ c_KILL_JOB
};
struct Command_line {
@@ -207,6 +208,7 @@
void c_show_output_file();
void c_remove_job();
void c_show_pid();
+void c_kill_job();
int c_wait_job();
int c_wait_running_job();
int c_wait_job_recv();