[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: looking for packages versions of running daemons



Javier Barroso <javibarroso@gmail.com> writes:

>> is this "xargs: echo: terminated by signal 13" the output it should be?
>Probably, substituting:

> bin=$(xargs -n 1 -0 echo < /proc/$pid/cmdline | awk '{print $1 ; exit}')

>with

>bin=$(awk '{print $1; exit}' /proc/$pid/cmdline)

>will solved the issue

>But I'm not sure why Cameron used xargs in this case.

/proc/pid/cmdline usually has ASCII NUL separated fields, which awk does
not split, so usually you have to use xargs -0. I noticed some cases
where the args were space separated (perl script), so I needed awk for
that case. I'll look more into awk and see if it can handle NULs in
some way. It doesn't by default.

The simple fix is to dump erors to /dev/null:
bin=$(xargs -n 1 -0 echo < /proc/$pid/cmdline 2>/dev/null | awk '{print $1 ; exit}')


Reply to: