/proc/${PID}/cmdline parsing
/proc/${PID}/cmdline parsing
am 03.06.2010 08:20:25 von Rakotomandimby Mihamina
Manao ahoana, Hello, Bonjour,
If I launch a
$ watch find / -type f -name 'toto'
(it's a useless command just for the example)
and then I get the PID of this.
When I
$ cat /proc/${PID}/cmdline
watchfind/-typef-nametoto
Yes, it's the command line, but I would like to parse it, in order to
display the launched executable + its arguments.
How to parse it?
Misaotra, Thanks, Merci.
--
Architecte Informatique chez Blueline/Gulfsat:
Administration Systeme, Recherche & Developpement
+261 3456 000 19
--
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Re: /proc/${PID}/cmdline parsing
am 03.06.2010 11:19:35 von Joel Fernandes
On Thu, Jun 03, 2010 at 09:20:25AM +0300, Mihamina Rakotomandimby wrote:
> Manao ahoana, Hello, Bonjour,
>
> If I launch a
> $ watch find / -type f -name 'toto'
> (it's a useless command just for the example)
> and then I get the PID of this.
PID of what? watch or find?
>
> When I
> $ cat /proc/${PID}/cmdline
> watchfind/-typef-nametoto
>
> Yes, it's the command line, but I would like to parse it, in order to
> display the launched executable + its arguments.
>
> How to parse it?
>
Could you be a bit more clear with your question?
take care,
Joel
--
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Re: /proc/${PID}/cmdline parsing
am 03.06.2010 11:29:29 von Rakotomandimby Mihamina
> Joel Fernandes :
>> If I launch a
>> $ watch find / -type f -name 'toto'
>> (it's a useless command just for the example)
>> and then I get the PID of this.
>PID of what? watch or find?
PID of "watch"
>> When I
>> $ cat /proc/${PID}/cmdline
>> watchfind/-typef-nametoto
>> Yes, it's the command line, but I would like to parse it, in order to
>> display the launched executable + its arguments.
>> How to parse it?
>Could you be a bit more clear with your question?
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?
--
Architecte Informatique chez Blueline/Gulfsat:
Administration Systeme, Recherche & Developpement
+261 3456 000 19
--
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Re: /proc/${PID}/cmdline parsing
am 03.06.2010 14:38:26 von Kristof Provost
On 2010-06-03 12:29:29 (+0300), Mihamina Rakotomandimby wrote:
> > Joel Fernandes :
> >> If I launch a
> >> $ watch find / -type f -name 'toto'
> >> (it's a useless command just for the example)
> >> and then I get the PID of this.
> >PID of what? watch or find?
>
> PID of "watch"
>
> >> When I
> >> $ cat /proc/${PID}/cmdline
> >> watchfind/-typef-nametoto
> >> Yes, it's the command line, but I would like to parse it, in order to
> >> display the launched executable + its arguments.
> >> How to parse it?
> >Could you be a bit more clear with your question?
>
> 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.
Kristof
--
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Re: /proc/${PID}/cmdline parsing
am 04.06.2010 23:05:50 von cyril
Kristof Provost a =E9crit :
> On 2010-06-03 12:29:29 (+0300), Mihamina Rakotomandimby
fsat.mg> wrote:
> =20
>>> Joel Fernandes :
>>> =20
>>>> If I launch a=20
>>>> $ watch find / -type f -name 'toto'
>>>> (it's a useless command just for the example)
>>>> and then I get the PID of this.
>>>> =20
>>> PID of what? watch or find?
>>> =20
>> PID of "watch"
>>
>> =20
>>>> When I=20
>>>> $ cat /proc/${PID}/cmdline
>>>> watchfind/-typef-nametoto
>>>> Yes, it's the command line, but I would like to parse it, in order=
to
>>>> display the launched executable + its arguments.
>>>> How to parse it?
>>>> =20
>>> Could you be a bit more clear with your question?
>>> =20
>> I want to split "watchfind/-typef-nametoto" (the content
>> of /proc/${PID}/cmdline) to get "watch find / -type f -name toto" (t=
he
>> 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?
>>
>> =20
>
> 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/get=
ty.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.
>
> Kristof
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-newbi=
e" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.linux-learn.org/faqs
> =20
You're right.
I'm no awk expert, so the following command might not be as beautiful a=
s=20
can be, but it does exactly what Mihamina wants :
$ cat /proc/PID/cmdline | awk '{BEGIN {FS =3D "\0"} ; {ORS =3D " "}; {f=
or (i=20
=3D 1 i < NF; i++) print $i}'
Cyril.
--
To unsubscribe from this list: send the line "unsubscribe linux-newbie"=
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
Re: /proc/${PID}/cmdline parsing
am 05.06.2010 11:39:22 von Joel Fernandes
>>> 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 =A02f 73 62 69 6e 2f 67 65 =A074 74 79 00 33 38 34 30
>> |/sbin/getty.3840|
>> 00000010 =A030 00 74 74 79 31 00 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 |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 =3D "\0"} ; {ORS =3D " "}; =
{for (i =3D 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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs