[PATCH 1/1] pidof - add option -q (quiet)
walter harms
wharms at bfs.de
Tue Jun 18 17:03:21 UTC 2019
when used in a script no output is needed. The latest version
of pidof supports the -q option to make thinks more easy.
Signed-off-by: walter <wharms at bfs.de>
---
I did not manage to have a usage() , can someone add this ?
---
procps/pidof.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/procps/pidof.c b/procps/pidof.c
index 5595e34..c6ee357 100644
--- a/procps/pidof.c
+++ b/procps/pidof.c
@@ -69,8 +69,10 @@
enum {
IF_FEATURE_PIDOF_SINGLE(OPTBIT_SINGLE,)
+ OPTBIT_QUIET ,
IF_FEATURE_PIDOF_OMIT( OPTBIT_OMIT ,)
OPT_SINGLE = IF_FEATURE_PIDOF_SINGLE((1<<OPTBIT_SINGLE)) + 0,
+ OPT_QUIET = (1<<OPTBIT_QUIET ) + 0,
OPT_OMIT = IF_FEATURE_PIDOF_OMIT( (1<<OPTBIT_OMIT )) + 0,
};
@@ -86,6 +88,7 @@ int pidof_main(int argc UNUSED_PARAM, char **argv)
/* do unconditional option parsing */
opt = getopt32(argv, ""
IF_FEATURE_PIDOF_SINGLE ("s")
+ "q"
IF_FEATURE_PIDOF_OMIT("o:*", &omits));
#if ENABLE_FEATURE_PIDOF_OMIT
@@ -121,7 +124,7 @@ int pidof_main(int argc UNUSED_PARAM, char **argv)
}
}
#endif
- printf(" %u" + first, (unsigned)*pl);
+ if (!(opt & OPT_QUIET)) printf(" %u" + first, (unsigned)*pl);
first = 0;
if (ENABLE_FEATURE_PIDOF_SINGLE && (opt & OPT_SINGLE))
break;
@@ -132,7 +135,7 @@ int pidof_main(int argc UNUSED_PARAM, char **argv)
free(pidList);
argv++;
}
- if (!first)
+ if (!first && !(opt & OPT_QUIET))
bb_putchar('\n');
#if ENABLE_FEATURE_PIDOF_OMIT
--
2.1.4
More information about the busybox
mailing list