From cca86db7bac0fbec80b63ebe5b15d7eec330dc26 Mon Sep 17 00:00:00 2001 From: csmall <> Date: Thu, 3 Oct 2002 23:08:14 +0000 Subject: [PATCH] added version stuff for kill and pgrep, tried to understand alberts groff and failed --- kill.1 | 1 + pgrep.c | 11 ++++++++++- skill.1 | 1 + skill.c | 26 ++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/kill.1 b/kill.1 index 66197dfe..f6870b8b 100644 --- a/kill.1 +++ b/kill.1 @@ -18,6 +18,7 @@ kill -s signal pid ... Send a signal to every process listed. kill -l List all signal names. kill -L List all signal names in a nice table. kill -l signal Convert a signal number into a name. +kill -V,--version Show version of program .TE .SH DESCRIPTION diff --git a/pgrep.c b/pgrep.c index 24d4e72c..61cd6d4b 100644 --- a/pgrep.c +++ b/pgrep.c @@ -25,6 +25,7 @@ #include "proc/sig.h" #include "proc/devname.h" #include "proc/sysinfo.h" +#include "proc/version.h" /* procps_version */ static int i_am_pkill = 0; char *progname = "pgrep"; @@ -64,6 +65,7 @@ static int conv_num (const char *, union el *); static int conv_str (const char *, union el *); static int match_numlist (long, const union el *); static int match_strlist (const char *, const union el *); +static void display_pgrep_version(void); static int @@ -109,7 +111,7 @@ parse_opts (int argc, char **argv) strcat (opts, "ld:"); } - strcat (opts, "fnvxP:g:s:u:U:G:t:?"); + strcat (opts, "fnvxP:g:s:u:U:G:t:?V"); while ((opt = getopt (argc, argv, opts)) != -1) { switch (opt) { @@ -176,6 +178,9 @@ parse_opts (int argc, char **argv) case '?': usage (opt); break; + case 'V': + display_pgrep_version(); + exit(0); } } if (argc - optind == 1) @@ -603,3 +608,7 @@ main (int argc, char **argv) } return ((procs[0].num) == 0 ? 1 : 0); } + +static void display_pgrep_version(){ + fprintf(stdout, "%s (%s)\n", progname, procps_version); +} diff --git a/skill.1 b/skill.1 index 643cffeb..57039545 100644 --- a/skill.1 +++ b/skill.1 @@ -37,6 +37,7 @@ Display information about selected processes. T} -w warnings enabled This is not currently useful. -n no action This only displays the process ID. +-V show version Displays version of program. .TE .SH "PROCESS SELECTION OPTIONS" diff --git a/skill.c b/skill.c index 7d784692..bbeff3f5 100644 --- a/skill.c +++ b/skill.c @@ -24,6 +24,7 @@ #include #include #include /* char *user_from_uid(uid_t uid) */ +#include "proc/version.h" /* procps_version */ static int f_flag, i_flag, v_flag, w_flag, n_flag; @@ -55,6 +56,23 @@ static int program; /********************************************************************/ +static void display_kill_version(){ + + switch(program) { + case PROG_KILL: + fprintf(stdout, "kill (%s)\n",procps_version); + return; + case PROG_SKILL: + fprintf(stdout, "skill (%s)\n",procps_version); + return; + case PROG_SNICE: + fprintf(stdout, "snice (%s)\n",procps_version); + return; + default: + fprintf(stdout, "unknown (%s)\n",procps_version); + return; + } +} /***** kill or nice a process */ static void hurt_proc(int tty, int uid, int pid, char *cmd){ @@ -232,6 +250,10 @@ static void kill_main(int argc, char *argv[]){ int signo = SIGTERM; int exitvalue = 0; if(argc<2) kill_usage(); + if(!strcmp(argv[1],"-V")|| !strcmp(argv[1],"--version")){ + display_kill_version(); + exit(0); + } if(argv[1][0]!='-'){ argv++; argc--; @@ -362,6 +384,10 @@ static void skillsnice_parse(int argc, char *argv[]){ unix_print_signals(); exit(0); } + if(!strcmp(argv[1],"-V")|| !strcmp(argv[1],"--version")){ + display_kill_version(); + exit(0); + } skillsnice_usage(); } NEXTARG;