All of lore.kernel.org
 help / color / mirror / Atom feed
* /proc/${PID}/cmdline parsing
@ 2010-06-03  6:20 Mihamina Rakotomandimby
  2010-06-03  9:19 ` Joel Fernandes
  0 siblings, 1 reply; 6+ messages in thread
From: Mihamina Rakotomandimby @ 2010-06-03  6:20 UTC (permalink / raw)
  To: linux-newbie

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: /proc/${PID}/cmdline parsing
  2010-06-03  6:20 /proc/${PID}/cmdline parsing Mihamina Rakotomandimby
@ 2010-06-03  9:19 ` Joel Fernandes
  2010-06-03  9:29   ` Mihamina Rakotomandimby
  0 siblings, 1 reply; 6+ messages in thread
From: Joel Fernandes @ 2010-06-03  9:19 UTC (permalink / raw)
  To: Mihamina Rakotomandimby; +Cc: linux-newbie

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: /proc/${PID}/cmdline parsing
  2010-06-03  9:19 ` Joel Fernandes
@ 2010-06-03  9:29   ` Mihamina Rakotomandimby
  2010-06-03 12:38     ` Kristof Provost
  0 siblings, 1 reply; 6+ messages in thread
From: Mihamina Rakotomandimby @ 2010-06-03  9:29 UTC (permalink / raw)
  To: linux-newbie

> Joel Fernandes <agnel.joel@gmail.com> :
>> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: /proc/${PID}/cmdline parsing
  2010-06-03  9:29   ` Mihamina Rakotomandimby
@ 2010-06-03 12:38     ` Kristof Provost
  2010-06-04 21:05       ` Cyril
  2010-06-05  9:39       ` Joel Fernandes
  0 siblings, 2 replies; 6+ messages in thread
From: Kristof Provost @ 2010-06-03 12:38 UTC (permalink / raw)
  To: Mihamina Rakotomandimby; +Cc: linux-newbie

On 2010-06-03 12:29:29 (+0300), Mihamina Rakotomandimby <mihamina@gulfsat.mg> wrote:
> > Joel Fernandes <agnel.joel@gmail.com> :
> >> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: /proc/${PID}/cmdline parsing
  2010-06-03 12:38     ` Kristof Provost
@ 2010-06-04 21:05       ` Cyril
  2010-06-05  9:39       ` Joel Fernandes
  1 sibling, 0 replies; 6+ messages in thread
From: Cyril @ 2010-06-04 21:05 UTC (permalink / raw)
  To: Kristof Provost; +Cc: Mihamina Rakotomandimby, linux-newbie



Kristof Provost a écrit :
> On 2010-06-03 12:29:29 (+0300), Mihamina Rakotomandimby <mihamina@gulfsat.mg> wrote:
>   
>>> Joel Fernandes <agnel.joel@gmail.com> :
>>>       
>>>> 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
>   

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}'

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: /proc/${PID}/cmdline parsing
  2010-06-03 12:38     ` Kristof Provost
  2010-06-04 21:05       ` Cyril
@ 2010-06-05  9:39       ` Joel Fernandes
  1 sibling, 0 replies; 6+ messages in thread
From: Joel Fernandes @ 2010-06-05  9:39 UTC (permalink / raw)
  To: Kristof Provost; +Cc: Mihamina Rakotomandimby, linux-newbie

>>> 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@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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-06-05  9:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-03  6:20 /proc/${PID}/cmdline parsing Mihamina Rakotomandimby
2010-06-03  9:19 ` Joel Fernandes
2010-06-03  9:29   ` Mihamina Rakotomandimby
2010-06-03 12:38     ` Kristof Provost
2010-06-04 21:05       ` Cyril
2010-06-05  9:39       ` Joel Fernandes

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.