`ps` from all versions checked and the current `master` uses a hard-coded width per field for output formatting. From `procps/ps.c` ``` static const ps_out_t out_spec[] = { /* Mandated by http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.ht ml: */ { 8 , "user" ,"USER" ,func_user ,PSSCAN_UIDGID }, { 8 , "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID }, { 16 , "comm" ,"COMMAND",func_comm ,PSSCAN_COMM }, { MAX_WIDTH , "args" ,"COMMAND",func_args ,PSSCAN_COMM }, { 5 , "pid" ,"PID" ,func_pid ,PSSCAN_PID }, { 5 , "ppid" ,"PPID" ,func_ppid ,PSSCAN_PPID }, { 5 , "pgid" ,"PGID" ,func_pgid ,PSSCAN_PGID }, ``` This works when the linux sysctl `kernel.pid_max` is at its default of 32768. However, if the value set to > 99999, it creates the potential for the `pid`, `ppid`, and `pgid` fields to be not only truncated upon output but with no delimiting space between it and the right hand side adjacent field. Eg., ``` / # ps -efo pid,comm PID COMMAND 1 dockerd 31 containerd 408249containerd-shim 408266cat 408786containerd-shim 408803cat 413819sh 414865ps ``` This is a bit of a disaster for programs that try to parse the output of `ps` and I've recently run into this with `docker`. Eg., https://github.com/moby/moby/issues/34282
Fixing in git: --- a/procps/ps.c +++ b/procps/ps.c @@ -533,7 +533,7 @@ static void format_process(const procps_status_t *ps) len = out[i].width - len + 1; if (++i == out_cnt) /* do not pad last field */ break; - p += sprintf(p, "%*s", len, ""); + p += sprintf(p, "%*s", len, " "); /* " ", not "", to ensure separation of fields */ } printf("%.*s\n", terminal_width, buffer); }