summaryrefslogtreecommitdiff
path: root/pidof.c
diff options
context:
space:
mode:
authorMasatake YAMATO <yamato@redhat.com>2018-02-24 18:03:11 +0900
committerCraig Small <csmall@enc.com.au>2018-03-02 21:48:23 +1100
commit7f5971058ae1a6241d03335e763a00f78da49737 (patch)
tree86535075938f08b157a548ada2ca8b3f658dc666 /pidof.c
parent1ddd17b17c99ba82af9a3758433f29bec3114802 (diff)
downloadprocps-ng-7f5971058ae1a6241d03335e763a00f78da49737.tar.gz
pidof: allow to change a separator put between pids
I frequency use pidof command with strace system call tracer. strace can trace MULTIPLE processes specified with "-p $PID" arguments like: strace -p 1 -p 1030 -p 3043 Sometimes I want to do as following strace -p $(pidof httpd) However, above command line doesn't work because -p option is needed for specifying a pid. pidof uses a whitespace as a separator. For passing the output to strace, the separator should be replaced with ' -p '. This maybe not a special to my use case. This commit introduces -S option that allows a user to specify a separator the one wants. $ ./pidof bash ./pidof bash 24624 18790 12786 11898 11546 10766 7654 5095 $ ./pidof -S ',' bash ./pidof -S ',' bash 24624,18790,12786,11898,11546,10766,7654,5095 $ ./pidof -S '-p ' bash ./pidof -S '-p ' bash 24624-p 18790-p 12786-p 11898-p 11546-p 10766-p 7654-p 5095 $ ./pidof -S ' -p ' bash ./pidof -S ' -p ' bash 24624 -p 18790 -p 12786 -p 11898 -p 11546 -p 10766 -p 7654 -p 5095 $ strace -p $(./pidof -S ' -p ' bash) strace -p $(./pidof -S ' -p ' bash) strace: Process 24624 attached strace: Process 18790 attached strace: Process 12786 attached ... Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Diffstat (limited to 'pidof.c')
-rw-r--r--pidof.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/pidof.c b/pidof.c
index 09087fb..ad79c29 100644
--- a/pidof.c
+++ b/pidof.c
@@ -65,6 +65,7 @@ static int __attribute__ ((__noreturn__)) usage(int opt)
fputs(_(" -c, --check-root omit processes with different root\n"), fp);
fputs(_(" -x also find shells running the named scripts\n"), fp);
fputs(_(" -o, --omit-pid <PID,...> omit processes with PID\n"), fp);
+ fputs(_(" -S, --separator SEP use SEP as separator put between PIDs"), fp);
fputs(USAGE_SEPARATOR, fp);
fputs(USAGE_HELP, fp);
fputs(USAGE_VERSION, fp);
@@ -290,12 +291,14 @@ int main (int argc, char **argv)
int found = 0;
int first_pid = 1;
- const char *opts = "scnxmo:?Vh";
+ const char *separator = " ";
+ const char *opts = "scnxmo:S:?Vh";
static const struct option longopts[] = {
{"check-root", no_argument, NULL, 'c'},
{"single-shot", no_argument, NULL, 's'},
{"omit-pid", required_argument, NULL, 'o'},
+ {"separator", required_argument, NULL, 's'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'V'},
{NULL, 0, NULL, 0}
@@ -327,6 +330,9 @@ int main (int argc, char **argv)
pidof_root = pid_link(getpid(), "root");
}
break;
+ case 'S':
+ separator = optarg;
+ break;
case 'V':
printf (PROCPS_NG_VERSION);
exit (EXIT_SUCCESS);
@@ -360,7 +366,7 @@ int main (int argc, char **argv)
first_pid = 0;
printf ("%ld", (long) procs[i].pid);
} else {
- printf (" %ld", (long) procs[i].pid);
+ printf ("%s%ld", separator, (long) procs[i].pid);
}
if (opt_single_shot) break;
}