ps -C behavior changed between Centos 6 and Centos 8

Our system often uses ps -C cmdName to check if a process is running and, if not, restart it.

In moving from Centos 6 to Centos 8 it seems the behavior of ps -C has changed which broke much of our system.

Centos 6 (32-bit)

Yes, process is there:

# ps aux | grep DvBuildSegmentList
root     16223  4.0  0.1  16064 11272 pts/0    S    14:14   0:00 ./DvBuildSegmentList
root     16264  0.0  0.0   4416  1880 pts/0    S+   14:14   0:00 grep DvBuildSegmentList

And ps -C on full command name detects the process:

# ps -C DvBuildSegmentList
  PID TTY          TIME CMD
16223 pts/0    00:00:00 DvBuildSegmentL

(note truncated command line in output)

Centos 8 (64-bit)

Yes, process is there:

# ps aux | grep DvBuildSeg
root     15282  0.9  0.2  99796 42424 pts/1    S    14:18   0:04 ./DvBuildSegmentList
root     16989  0.0  0.0 221900  1104 pts/1    S+   14:26   0:00 grep --color=auto DvBuildSeg

Using full command name has no output:

# /bin/ps -C DvBuildSegmentList
  PID TTY          TIME CMD

But using a shortened command name does detect the process:

# /bin/ps -C DvBuildSegmentL
  PID TTY          TIME CMD
15282 pts/1    00:00:06 DvBuildSegmentL

We need to maintain both the 32-bit Centos 6 and the 64-bit Centos 8, ideally without re-writing a lot of code.

  1. Is there a way to get the same behavior of ps between versions? (might not be able to truncate the command name to the first 15 characters because of name collisions)

  2. Is there another approach to detect the process? (There’s a lot of code and the ps -C approach is sprinkled across C++, perl, php, and bash)

Leave a Reply

Your email address will not be published. Required fields are marked *