diff --git a/README.md b/README.md index 2693fde..4eacee8 100755 --- a/README.md +++ b/README.md @@ -70,52 +70,53 @@ See below/`man ts`/`ts -h` for more details. ``` usage: ts [action] [-ngfmdE] [-L ] [-D ] [cmd...] Env vars: - TS_VISIBLE_DEVICES the GPU IDs that are visible to ts. Jobs will be run on these GPUs only. - TS_SOCKET the path to the unix socket used by the ts command. - TS_MAILTO where to mail the result (on -m). Local user by default. - TS_MAXFINISHED maximum finished jobs in the queue. - TS_MAXCONN maximum number of ts connections at once. - TS_ONFINISH binary called on job end (passes jobid, error, outfile, command). - TS_ENV command called on enqueue. Its output determines the job information. - TS_SAVELIST filename which will store the list, if the server dies. - TS_SLOTS amount of jobs which can run at once, read on server start. - TMPDIR directory where to place the output files and the default socket. + TS_VISIBLE_DEVICES the GPU IDs that are visible to ts. Jobs will be run on these GPUs only. + TS_SOCKET the path to the unix socket used by the ts command. + TS_MAILTO where to mail the result (on -m). Local user by default. + TS_MAXFINISHED maximum finished jobs in the queue. + TS_MAXCONN maximum number of ts connections at once. + TS_ONFINISH binary called on job end (passes jobid, error, outfile, command). + TS_ENV command called on enqueue. Its output determines the job information. + TS_SAVELIST filename which will store the list, if the server dies. + TS_SLOTS amount of jobs which can run at once, read on server start. + TMPDIR directory where to place the output files and the default socket. Long option actions: - --getenv [var] get the value of the specified variable in server environment. - --setenv [var] set the specified flag to server environment. ---unsetenv [var] remove the specified flag from server environment. - --set_gpu_free_perc [num] set the value of GPU memory threshold above which GPUs are considered available (90 by default). - --get_gpu_free_perc get the value of GPU memory threshold above which GPUs are considered available. - --get_label || -a [id] show the job label. Of the last added, if not specified. - --full_cmd || -F [id] show full command. Of the last added, if not specified. - --count_running || -R return the number of running jobs - --last_queue_id || -q show the job ID of the last added. - --get_logdir get the path containing log files. - --set_logdir [path] set the path containing log files. + --getenv [var] get the value of the specified variable in server environment. + --setenv [var] set the specified flag to server environment. + --unsetenv [var] remove the specified flag from server environment. + --set_gpu_free_perc [num] set the value of GPU memory threshold above which GPUs are considered available (90 by default). + --get_gpu_free_perc get the value of GPU memory threshold above which GPUs are considered available. + --get_label || -a [id] show the job label. Of the last added, if not specified. + --full_cmd || -F [id] show full command. Of the last added, if not specified. + --count_running || -R return the number of running jobs + --last_queue_id || -q show the job ID of the last added. + --get_logdir get the path containing log files. + --set_logdir [path] set the path containing log files. + --serialize [format] || -M [format] serialize the job list to the specified format. Choices: {default, json, tab}. Long option adding jobs: - --gpus || -G [num] number of GPUs required by the job (1 default). - --gpu_indices || -g [id,...] the job will be on these GPU indices without checking whether they are free. + --gpus || -G [num] number of GPUs required by the job (1 default). + --gpu_indices || -g [id,...] the job will be on these GPU indices without checking whether they are free. Actions (can be performed only one at a time): - -K kill the task spooler server - -C clear the list of finished jobs - -l show the job list (default action) - -g list all jobs running on GPUs and the corresponding GPU IDs - -S [num] get/set the number of max simultaneous jobs of the server. - -t [id] \"tail -n 10 -f\" the output of the job. Last run if not specified. - -c [id] like -t, but shows all the lines. Last run if not specified. - -p [id] show the pid of the job. Last run if not specified. - -o [id] show the output file. Of last job run, if not specified. - -i [id] show job information. Of last job run, if not specified. - -s [id] show the job state. Of the last added, if not specified. - -r [id] remove a job. The last added, if not specified. - -w [id] wait for a job. The last added, if not specified. - -k [id] send SIGTERM to the job process group. The last run, if not specified. - -T send SIGTERM to all running job groups. - -u [id] put that job first. The last added, if not specified. - -U [id-id] swap two jobs in the queue. - -B in case of full queue on the server, quit (2) instead of waiting. - -h show this help - -V show the program version + -K kill the task spooler server + -C clear the list of finished jobs + -l show the job list (default action) + -g list all jobs running on GPUs and the corresponding GPU IDs + -S [num] get/set the number of max simultaneous jobs of the server. + -t [id] \"tail -n 10 -f\" the output of the job. Last run if not specified. + -c [id] like -t, but shows all the lines. Last run if not specified. + -p [id] show the pid of the job. Last run if not specified. + -o [id] show the output file. Of last job run, if not specified. + -i [id] show job information. Of last job run, if not specified. + -s [id] show the job state. Of the last added, if not specified. + -r [id] remove a job. The last added, if not specified. + -w [id] wait for a job. The last added, if not specified. + -k [id] send SIGTERM to the job process group. The last run, if not specified. + -T send SIGTERM to all running job groups. + -u [id] put that job first. The last added, if not specified. + -U [id-id] swap two jobs in the queue. + -B in case of full queue on the server, quit (2) instead of waiting. + -h show this help + -V show the program version Options adding jobs: -n don't store the output of the command. -E Keep stderr apart, in a name like the output file, but adding '.e'. @@ -124,10 +125,10 @@ Options adding jobs: -f don't fork into background. -m send the output by e-mail (uses sendmail). -d the job will be run after the last job ends. - -D the job will be run after the job of given IDs ends. - -W the job will be run after the job of given IDs ends well (exit code 0). - -L name this task with a label, to be distinguished on listing. - -N number of slots required by the job (1 default). + -D [id,...] the job will be run after the job of given IDs ends. + -W [id,...] the job will be run after the job of given IDs ends well (exit code 0). + -L [lab] name this task with a label, to be distinguished on listing. + -N [num] number of slots required by the job (1 default). ``` ## People diff --git a/main.c b/main.c index d8bbd1f..c19ffbe 100755 --- a/main.c +++ b/main.c @@ -112,10 +112,11 @@ int strtok_int(char* str, char* delim, int* ids) { } static struct option longOptions[] = { - {"get_label", optional_argument, NULL, 'a'}, + {"get_label", required_argument, NULL, 'a'}, {"count_running", no_argument, NULL, 'R'}, {"last_queue_id", no_argument, NULL, 'q'}, - {"full_cmd", optional_argument, NULL, 'F'}, + {"full_cmd", required_argument, NULL, 'F'}, + {"serialize", required_argument, NULL, 'M'}, {"getenv", required_argument, NULL, 0}, {"setenv", required_argument, NULL, 0}, {"unsetenv", required_argument, NULL, 0}, @@ -326,6 +327,20 @@ void parse_opts(int argc, char **argv) { case 'R': command_line.request = c_COUNT_RUNNING; break; + case 'M': + command_line.request = c_LIST; + + if (strcmp(optarg, "default") == 0) + command_line.list_format = DEFAULT; + else if (strcmp(optarg, "json") == 0) + command_line.list_format = JSON; + else if (strcmp(optarg, "tab") == 0) + command_line.list_format = TAB; + else { + fprintf(stderr, "Invalid argument for option M: %s.\n", optarg); + exit(-1); + } + break; case ':': switch (optopt) { case 't': @@ -383,6 +398,10 @@ void parse_opts(int argc, char **argv) { command_line.request = c_SHOW_CMD; command_line.jobid = -1; break; + case 'M': + command_line.request = c_LIST; + command_line.list_format = DEFAULT; + break; #ifndef CPU case 'g': command_line.request = c_LIST_GPU; @@ -394,23 +413,6 @@ void parse_opts(int argc, char **argv) { exit(-1); } break; - case 'M': - if (command_line.request != c_LIST) { - fprintf(stderr, "-M can only be used when listing jobs.\n"); - exit(-1); - } - - if (strcmp(optarg, "default") == 0) - command_line.list_format = DEFAULT; - else if (strcmp(optarg, "json") == 0) - command_line.list_format = JSON; - else if (strcmp(optarg, "tab") == 0) - command_line.list_format = TAB; - else { - fprintf(stderr, "Invalid argument for option M: %s.\n", optarg); - exit(-1); - } - break; case '?': fprintf(stderr, "Wrong option %c.\n", optopt); exit(-1); @@ -483,31 +485,32 @@ static void print_help(const char *cmd) { #ifndef CPU printf(" TS_VISIBLE_DEVICES the GPU IDs that are visible to ts. Jobs will be run on these GPUs only.\n"); #endif - printf(" TS_SOCKET the path to the unix socket used by the ts command.\n"); - printf(" TS_MAILTO where to mail the result (on -m). Local user by default.\n"); - printf(" TS_MAXFINISHED maximum finished jobs in the queue.\n"); - printf(" TS_MAXCONN maximum number of ts connections at once.\n"); - printf(" TS_ONFINISH binary called on job end (passes jobid, error, outfile, command).\n"); - printf(" TS_ENV command called on enqueue. Its output determines the job information.\n"); - printf(" TS_SAVELIST filename which will store the list, if the server dies.\n"); - printf(" TS_SLOTS amount of jobs which can run at once, read on server start.\n"); - printf(" TMPDIR directory where to place the output files and the default socket.\n"); + printf(" TS_SOCKET the path to the unix socket used by the ts command.\n"); + printf(" TS_MAILTO where to mail the result (on -m). Local user by default.\n"); + printf(" TS_MAXFINISHED maximum finished jobs in the queue.\n"); + printf(" TS_MAXCONN maximum number of ts connections at once.\n"); + printf(" TS_ONFINISH binary called on job end (passes jobid, error, outfile, command).\n"); + printf(" TS_ENV command called on enqueue. Its output determines the job information.\n"); + printf(" TS_SAVELIST filename which will store the list, if the server dies.\n"); + printf(" TS_SLOTS amount of jobs which can run at once, read on server start.\n"); + printf(" TMPDIR directory where to place the output files and the default socket.\n"); printf("Long option actions:\n"); - printf(" --getenv [var] get the value of the specified variable in server environment.\n"); - printf(" --setenv [var] set the specified flag to server environment.\n"); - printf(" --unsetenv [var] remove the specified flag from server environment.\n"); - printf(" --get_label || -a [id] show the job label. Of the last added, if not specified.\n"); - printf(" --full_cmd || -F [id] show full command. Of the last added, if not specified.\n"); - printf(" --count_running || -R return the number of running jobs\n"); - printf(" --last_queue_id || -q show the job ID of the last added.\n"); - printf(" --get_logdir get the path containing log files.\n"); - printf(" --set_logdir [path] set the path containing log files.\n"); + printf(" --getenv [var] get the value of the specified variable in server environment.\n"); + printf(" --setenv [var] set the specified flag to server environment.\n"); + printf(" --unsetenv [var] remove the specified flag from server environment.\n"); + printf(" --get_label || -a [id] show the job label. Of the last added, if not specified.\n"); + printf(" --full_cmd || -F [id] show full command. Of the last added, if not specified.\n"); + printf(" --count_running || -R return the number of running jobs\n"); + printf(" --last_queue_id || -q show the job ID of the last added.\n"); + printf(" --get_logdir get the path containing log files.\n"); + printf(" --set_logdir [path] set the path containing log files.\n"); + printf(" --serialize [format] || -M [format] serialize the job list to the specified format. Choices: {default, json, tab}.\n"); #ifndef CPU - printf(" --set_gpu_free_perc [num] set the value of GPU memory threshold above which GPUs are considered available (90 by default).\n"); - printf(" --get_gpu_free_perc get the value of GPU memory threshold above which GPUs are considered available.\n"); + printf(" --set_gpu_free_perc [num] set the value of GPU memory threshold above which GPUs are considered available (90 by default).\n"); + printf(" --get_gpu_free_perc get the value of GPU memory threshold above which GPUs are considered available.\n"); printf("Long option adding jobs:\n"); - printf(" --gpus || -G [num] number of GPUs required by the job (1 default).\n"); - printf(" --gpu_indices || -g [id,...] the job will be on these GPU indices without checking whether they are free.\n"); + printf(" --gpus || -G [num] number of GPUs required by the job (1 default).\n"); + printf(" --gpu_indices || -g [id,...] the job will be on these GPU indices without checking whether they are free.\n"); #endif printf("Actions (can be performed only one at a time):\n"); printf(" -K kill the task spooler server\n"); @@ -529,7 +532,6 @@ static void print_help(const char *cmd) { printf(" -T send SIGTERM to all running job groups.\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(" -M [format] Print output in a machine-readable format. Choices: {default, json, tab}.\n"); printf(" -h show this help\n"); printf(" -V show the program version\n"); printf("Options adding jobs:\n"); diff --git a/man.c b/man.c index 72494ef..7375497 100644 --- a/man.c +++ b/man.c @@ -32,7 +32,6 @@ int main() { ".sp\n" "Actions:\n" ".BI \"[\\-KClhVTRqMg]\n" - ".BI \"[\\-M [\"format ]]\n" ".BI \"[\\-t [\"id ]]\n" ".BI \"[\\-c [\"id ]]\n" ".BI \"[\\-p [\"id ]]\n" @@ -54,6 +53,7 @@ int main() { ".BI \"[\\--set_gpu_free_perc ]\n" ".BI \"[\\--get_logdir]\n" ".BI \"[\\--set_logdir [\"path ]]\n" + ".BI \"[\\-M/--serialize [\"format ]]\n" "\n" ".sp\n" "Options:\n" @@ -204,8 +204,8 @@ int main() { ".B ts\n" "is called without options.\n" ".TP\n" - ".B \"\\-M [format]\"\n" - "Print output in a machine-readable format. Choices: {default, json, tab}.\n" + ".B \"\\-M/--serialize [format]\"\n" + "Serialize the job list to the specified format. Choices: {default, json, tab}.\n" ".TP\n" ".B \"\\-g\"\n" "list all jobs running on GPUs and the corresponding GPU IDs.\n" @@ -435,7 +435,6 @@ int main() { ".sp\n" "Actions:\n" ".BI \"[\\-KClhVTRqM]\n" - ".BI \"[\\-M [\"format ]]\n" ".BI \"[\\-t [\"id ]]\n" ".BI \"[\\-c [\"id ]]\n" ".BI \"[\\-p [\"id ]]\n" @@ -455,6 +454,7 @@ int main() { ".BI \"[\\--unsetenv [\"var ]]\n" ".BI \"[\\--get_logdir]\n" ".BI \"[\\--set_logdir [\"path ]]\n" + ".BI \"[\\-M/--serialize [\"format ]]\n" "\n" ".sp\n" "Options:\n" @@ -591,8 +591,8 @@ int main() { ".B ts\n" "is called without options.\n" ".TP\n" - ".B \"\\-M [format]\"\n" - "Print output in a machine-readable format. Choices: {default, json, tab}.\n" + ".B \"\\-M/--serialize [format]\"\n" + "Serialize the job list to the specified format. Choices: {default, json, tab}.\n" ".TP\n" ".B \"\\-q/--last_queue_id\"\n" "Show the job ID of the last added.\n"