[PATCH 1/1] pidof - add option -q (quiet)

walter harms wharms at bfs.de
Thu Jun 20 13:56:29 UTC 2019


Hi,
i was not aware that procps-ng has its own version,
NTL the option is handy in scripting.

http://git.savannah.nongnu.org/cgit/sysvinit.git/tree/src/killall5.c

see:main_pidof (or pidof_usage), i have just notice that it is missing
in the SYNOPSIS section of the man page.

re,
 wh

Am 20.06.2019 15:33, schrieb Denys Vlasenko:
> Not compatible with procps-ng 3.3.15
> 
> Which version of pidof has this option?
> 
> On Tue, Jun 18, 2019 at 7:03 PM walter harms <wharms at bfs.de> wrote:
>>
>> 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
>>
>> _______________________________________________
>> busybox mailing list
>> busybox at busybox.net
>> http://lists.busybox.net/mailman/listinfo/busybox
> 


More information about the busybox mailing list