0

The setup is I have two folders now under my current directory, busybox-1.36.1 and procps-4.0.4, and I also have a service languagetool running with DynamicUser=yes. Now observe the different behaviour:

Legend: ✅ Doesn't truncate; ❌ truncates.

busybox watch & busybox ps ✅

./busybox-1.36.1/bin/watch './busybox-1.36.1/bin/ps aux | grep languagetool' 
Every 2.0s: ./busybox-1.36.1/bin/ps aux | grep languagetool 2025-03-17 23:20:02 1026972 61534 39:36 java ...languagetool... 4053857 mathiass 0:00 ./busybox-1.36.1/bin/watch ./busybox-1.36.1/bin/ps aux | grep languagetool 4053882 mathiass 0:00 sh -c -- ./busybox-1.36.1/bin/ps aux | grep languagetool 4053884 mathiass 0:00 grep languagetool 

busybox watch & procps ps ✅

./busybox-1.36.1/bin/watch './procps-4.0.4/bin/ps aux | grep languagetool' 
Every 2.0s: ./procps-4.0.4/bin/ps aux | grep languagetool languag+ 1026972 0.1 13.6 14468788 4464816 ? Ssl Mar04 39:38 java ...languagetool... mathias+ 4057218 0.0 0.0 4676 2244 pts/32 S+ 23:35 0:00 ./busybox-1.36.1/bin/watch ./procps-4.0.4/bin/ps aux | grep languagetool mathias+ 4057222 0.0 0.0 231736 3788 pts/32 S+ 23:35 0:00 sh -c -- ./procps-4.0.4/bin/ps aux | grep languagetool mathias+ 4057224 0.0 0.0 230732 2520 pts/32 S+ 23:35 0:00 grep languagetool 

procps watch & procps ps ❌

./procps-4.0.4/bin/watch './procps-4.0.4/bin/ps aux | grep languagetool' 
Every 2.0s: ./procps-4.0.4/bin/ps aux | grep languagetool mathias+ 4056463 0.0 0.0 230836 3320 pts/32 S+ 23:31 0:00 ./procps-4.0.4/bin/watch ./procps-4.0.4/bin/ps aux | grep languagetool mathias+ 4056540 0.0 0.0 230836 1532 pts/32 S+ 23:32 0:00 ./procps-4.0.4/bin/watch ./procps-4.0.4/bin/ps aux | grep languagetool mathias+ 4056541 0.0 0.0 231736 3556 pts/32 S+ 23:32 0:00 sh -c -- ./procps-4.0.4/bin/ps aux | grep languagetool mathias+ 4056543 0.0 0.0 230732 2244 pts/32 S+ 23:32 0:00 grep languagetool 

procps watch & busybox ps ✅

./procps-4.0.4/bin/watch './busybox-1.36.1/bin/ps aux | grep languagetool' 
Every 2.0s: ./busybox-1.36.1/bin/ps aux | grep languagetool nixos: Mon Mar 17 23:33:31 2025 1026972 61534 39:38 java ...languagetool... 4056826 mathiass 0:00 ./procps-4.0.4/bin/watch ./busybox-1.36.1/bin/ps aux | grep languagetool 4056831 mathiass 0:00 ./procps-4.0.4/bin/watch ./busybox-1.36.1/bin/ps aux | grep languagetool 4056832 mathiass 0:00 sh -c -- ./busybox-1.36.1/bin/ps aux | grep languagetool 4056834 mathiass 0:00 grep languagetool 

Question

It seems odd that in every other case the commands behave as I expect them to, except when trying to use both ps and watch from procps. Does anybody know what is going on here?

2
  • Do you see the truncation if you don't pipe the output, but instead let it go to your terminal window? Or redirect the output to a file? Commented Mar 18 at 2:54
  • @SottoVoce I am not sure what you are asking, do you mean just running /prcocps-4.0.4/bin/ps aux if so yes it of doesn't truncate, but it is hard to tell if /prcocps-4.0.4/bin/watch /prcocps-4.0.4/bin/ps aux truncates or not because the first lines what watch displays aren't enough to determine that... But If it does or not, that still doesn't explain the behaviour above. Commented Mar 18 at 3:50

2 Answers 2

1

Normally, when the output doesn't go to a terminal, procps' ps does not truncate command lines, but that's unless the $COLUMNS environment variable is set and the procps implementation of watch does happen to set it based on the width of the terminal it is running in¹.

But here, rather than running ps | grep (here using non-standard ps aux API that is actually ignored by busybox ps), you could just do:

watch 'pgrep -af languagetool' 

(or watch -x pgrep -af languagetool with procps' watch to avoid the unnecessary shell invocations).

pgrep, with -f will match the regexp against the full² process argument list³ only and not report itself or its ancestry (such as the watch command here).

Note that while busybox does have a pgrep applet, it's not always enabled.

Here, to match on command line only without including the sh, grep/awk and watch commands portably between procps and busybox implementations of ps, you could do:

watch ' COLUMNS=0 ps -o args= | awk "/languagetool/ && ! /exclude-me-please/" ' 

¹ Shells such as ksh, zsh, bash or fish also set a $COLUMNS shell variable (not when non-interactive in the case of bash) but do not export it to the environment by default.

² Or as much it is possible to obtain as earlier versions of the Linux kernel only made the first 4096 bytes available.

³ Joined with spaces and with transformation of some characters such as control ones similarly to what ps -wwo args does.

1

What seems to be happening is behavior that the procps man page discusses, altough it's not in the most obvious place. Halfway or more down the page there's a section titled STANDARD FORMAT SPECIFIERS describing keywords used with the -o option. The section lists in table format each specifier word, its header title, and a description of the info it displays.

The specific option to examine is "args". The DESCRIPTION field for args is fairly long, but begins by saying the output is the command and the arguments. Farther into the description we find:

 If ps can not determine display width, as when output is redirected (piped) into a file or another command, the output width is undefined (it may be 80, unlimited, determined by the TERM variable, and so on). The COLUMNS environment variable or --cols option may be used to exactly determine the width in this case. The w or -w option may be also be used to adjust width. 

What it's saying is that procps tries to figure out the width of the terminal window it's outputting to. It doesn't matter whether you use -o args or not, procps always does this. When it cannot figure out the width - usually because its output isn't going directly to a terminal window - procps may choose a width that you don't like.

So the truncation is most likely a side effect of piping the output to the grep command. As the above indicates, adding w to the procps options like this:

./busybox-1.36.1/bin/ps auxw | grep languagetool 

may overcome the issue, or invoking it with the COLUMNS variable set to a larger value like this:

COLUMNS=200 ./busybox-1.36.1/bin/ps aux | grep languagetool 

may work better.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.