Re: /proc/${PID}/cmdline parsing

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

 



>>> I want to split "watchfind/-typef-nametoto" (the content
>>> of /proc/${PID}/cmdline) to get "watch find / -type f -name toto" (the
>>> command I issued above)
>>>
>>> But I cannot figure out how to split it.
>>> Would you know another place in the system I should look at?
>>>
>>>
>>
>> Running 'hexdump -C /proc/2202/cmdline' produces this:
>>
>> 00000000  2f 73 62 69 6e 2f 67 65  74 74 79 00 33 38 34 30
>> |/sbin/getty.3840|
>> 00000010  30 00 74 74 79 31 00                             |0.tty1.|
>> 00000017
>>
>> It looks like the fields are separated by 0 bytes.
>> You'll simply need to read the file and split on every zero byte.
>
> You're right.
>
> I'm no awk expert, so the following command might not be as beautiful as can
> be, but it does exactly what Mihamina wants :
>
> $ cat /proc/PID/cmdline | awk '{BEGIN {FS = "\0"} ; {ORS = " "}; {for (i = 1
> i < NF; i++) print $i}'
>

While we're at it, here's a perl one-liner :-)
cat /proc/self/cmdline | perl -F"\0" -lane 'foreach(@F) { print; }'

take care,
Joel
--
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs


[Index of Archives]     [Audio]     [Hams]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Fedora Users]

  Powered by Linux