Bug#1127408: pstree incorrectly displays and duplicates arguments for sh -c commands

2026-02-08 Thread Craig Small
Hi Marc,

On Sun, 8 Feb 2026 at 19:21, Marc Haber 
wrote:

Actual Output:
> |-bash,223670
> |   `-git,229284 log --max-count=1
> |   `-sh,229285 -c less -F -R -X less -F -R -X
> |   `-less,229286 -F -R -X
>
> The command string less -F -R -X appears twice on the sh line
>
[...]

> Running `ps` on the `less` process confirms only one instance exists
> with correct arguments:
>
> $ ps 229286
>PID TTY  STAT   TIME COMMAND
> 229286 pts/10   S+ 0:00 less -F -R -X
>

The line with the duplicate is 229285 not 229286. pstree correctly shows
the same as ps for 229286.
Try doing the same ps command for 229285.

$ pstree -apl | grep -A 3 gi[t]
  |   |   |   `-git,7392 log --max-count=45
  |   |   |   `-sh,7393 -c less -A -F -X less -A -F -X
  |   |   |   `-less,7394 -A -F -X
  |   |   |-bash,5332
$ ps 7393 7394
PID TTY  STAT   TIME COMMAND
   7393 pts/0S+ 0:00 /bin/sh -c less -A -F -X less -A -F -X
   7394 pts/0S+ 0:00 less -A -F -X

The duplicates are what the kernel is reporting, the ^@ is nul which
separates command line options.
$ cat -e /proc/7393/cmdline
/bin/sh^@-c^@less -A -F -X^@less -A -F -X^@

So yes, I totally agree it looks strange, but the strangeness is actually
there!

Perhaps this is a wishlist bug and you want pstree to change the output if
it is duplicated?
The big problem with that is, pstree and ps do not change what they get and
I don't see a bulletproof
way of pstree knowing when is the right time to remove duplicates.

I'd probably get mirrored bug reports, like "pstree reports prog -foo but
ps shows prog -foo -foo".

 - Craig


Bug#1127408: pstree incorrectly displays and duplicates arguments for sh -c commands

2026-02-08 Thread Marc Haber
Package: psmisc
Version: 23.7-2
Severity: minor
File: /usr/bin/pstree

Thanks for providing pstree. I use it almost daily instead of having to 
remember the proper options for ps.

When using pstree -apl, shell commands invoked via sh -c have their 
arguments displayed incorrectly - they appear duplicated. Parenthetical 
formatting would help to distinguish them from process names.

This makes legitimate process trees appear broken and causes users to 
troubleshoot non-existent configuration issues.

Steps to Reproduce:

Start a process that uses sh -c to invoke a command with arguments, such 
as:

$ git log --max-count=1
(Git uses sh -c to invoke the pager)

Keep the pager open. Run pstree -apl in a different window and search 
for the git log process

The sh -c invocation should display arguments like this (suggested 
formatting):

|-bash,223670
|   `-git,229284 log --max-count=1
|   `-sh,229285 -c less -F -R -X
|   `-less,229286 -F -R -X

If the process replaces its name, parenthesis could/should be used.

Actual Output:
|-bash,223670
|   `-git,229284 log --max-count=1
|   `-sh,229285 -c less -F -R -X less -F -R -X
|   `-less,229286 -F -R -X

The command string less -F -R -X appears twice on the sh line

This creates confusion. It looks like something is misconfigured when 
it's actually normal

Running `ps` on the `less` process confirms only one instance exists 
with correct arguments:

$ ps 229286
   PID TTY  STAT   TIME COMMAND
229286 pts/10   S+ 0:00 less -F -R -X

-- System Information:
Debian Release: forky/sid
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 
'oldstable-security'), (500, 'unstable'), (500, 'testing'), (500, 'stable'), 
(500, 'oldstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 6.18.8+deb14-amd64 (SMP w/12 CPU threads; PREEMPT)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8), LANGUAGE=en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages psmisc depends on:
ii  libc6  2.42-11+b1
ii  libtinfo6  6.6+20251231-1

psmisc recommends no packages.

psmisc suggests no packages.

-- no debconf information