Friday, February 06, 2026

Re: How to get process command line?

On 2026/02/06 15:59, Thomas Kupper wrote:
>
> On 06.02.2026 15:01, Stuart Henderson wrote:
> > On 2026-02-06, Thomas Kupper <mailing.list@kupper.li> wrote:
> > > Hi,
> > >
> > > I'm playing around with Chrony and used setproctitle() to set the title
> > > of the involved process (main, helper and NTS helper).
> > >
> > > And I can't figure out how to receive the command line the application
> > > was started with after using setproctitle().
> > >
> > > E.g. running 'ps -o command' outputs before setproctitle():
> > >
> > > $ ps -auxo command | fgrep chronyd
> > > _chrony 43240 <snip> chronyd -F 0 -u _chrony -d -f /etc/chrony.conf
> > > _chrony 77494 <snip> chronyd -F 0 -u _chrony -d -f /etc/chrony.conf
> > > root 18016 <snip> chronyd -F 0 -u _chrony -d -f /etc/chrony.conf
> > >
> > > running 'ps -o command' outputs after setproctitle():
> > >
> > > $ ps -auxo command | fgrep chronyd
> > > _chrony 47331 <snip> chronyd: server (chronyd)
> > > _chrony 64136 <snip> chronyd: NTS helper (chronyd)
> > > root 56489 <snip> chronyd: PRV helper (chronyd)
> > >
> > > What tool would show the calling command line? Would someone be able to
> > > nudge me into the right direction?
> >
> > You would need to save it before calling setproctitle (depending on
> > exactly what you want this for, you could possibly change the
> > setproctitle call to add the contents of argv)
>
> Thank you Stuart, I will then not set the process title for the first one
> (server). That seems the easiest way. Mmh or add it at the end as you
> suggested (like pflogd).

btw, pflogd is extra-special, and builds its own title string based on what
the flags do, but doesn't use them directly - hence the poor handling in
rc scripts :)

skipping for the first process seems sane, and I guess ps -f / pstree will
make it fairly easy to associate helpers with the main process if needed.

> I thought that maybe something similar to /proc/<proc id>/cmdline would
> exists and I was just to thick to find it.
>
> It was generally meant as an easy way to see the command line arguments used
> to start a application, mostly for debugging purposes (httpd, sshd, ).

No comments:

Post a Comment