From: Cyril <tipecaml@gmail.com>
To: Kristof Provost <kristof@sigsegv.be>
Cc: Mihamina Rakotomandimby <mihamina@gulfsat.mg>,
linux-newbie@vger.kernel.org
Subject: Re: /proc/${PID}/cmdline parsing
Date: Fri, 04 Jun 2010 23:05:50 +0200 [thread overview]
Message-ID: <4C096AAE.3000904@gmail.com> (raw)
In-Reply-To: <20100603123825.GE4720@nereid>
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
next prev parent reply other threads:[~2010-06-04 21:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2010-06-05 9:39 ` Joel Fernandes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C096AAE.3000904@gmail.com \
--to=tipecaml@gmail.com \
--cc=kristof@sigsegv.be \
--cc=linux-newbie@vger.kernel.org \
--cc=mihamina@gulfsat.mg \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.