commit 1927d289903e1729699e7ee95161b652799f1106
parent 6a1970caa4fce81899ece1ef4da614ed33b6554d
Author: sin <sin@2f30.org>
Date: Sat, 31 Aug 2013 17:33:45 +0100
Add single shot option for pidof(8)
Diffstat:
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/pidof.c b/pidof.c
@@ -10,7 +10,7 @@
static void
usage(void)
{
- eprintf("usage: %s [program...]\n", argv0);
+ eprintf("usage: %s [-s] [program...]\n", argv0);
}
int
@@ -22,8 +22,12 @@ main(int argc, char *argv[])
struct procstat ps;
char cmdline[BUFSIZ], *cmd, *p;
int i, found = 0;
+ int sflag = 0;
ARGBEGIN {
+ case 's':
+ sflag = 1;
+ break;
default:
usage();
} ARGEND;
@@ -51,10 +55,13 @@ main(int argc, char *argv[])
if (strcmp(cmd, argv[i]) == 0) {
putword(entry->d_name);
found++;
+ if (sflag)
+ goto out;
}
}
}
+out:
if (found)
putchar('\n');