Bug 1803640

Summary: pidof is broken for kernel threads
Product: Red Hat Enterprise Linux 8 Reporter: Malahal <mnaineni>
Component: procps-ngAssignee: Jan Rybar <jrybar>
Status: CLOSED ERRATA QA Contact: Karel Volný <kvolny>
Severity: high Docs Contact:
Priority: low    
Version: 8.1CC: atolani, bhill, kvolny
Target Milestone: rc   
Target Release: 8.0   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: procps-ng-3.3.15-2.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-11-04 01:38:34 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1969400    

Description Malahal 2020-02-17 05:31:42 UTC
Description of problem:


Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1.
2.
3.

Actual results:


Expected results:


Additional info:

Comment 1 Malahal 2020-02-17 05:34:10 UTC
For example: "pidof kswapd0" returns empty list on RHEL8.x but return a PID on RHEL7.x

Comment 2 Malahal 2020-02-17 05:36:22 UTC
In pidof.c file, if task.cmdline is not available (not available for kernel threads), using task.cmd is an option to fix this.

Comment 3 Jan Rybar 2020-04-07 13:56:03 UTC
Hello Malahal,

first, I will explain the pidof's behaviour you're experiencing.
Pidof in RHEL7 was part of sysvinit-tools component. Since sysvinit-tools was abandoned in RHEL8, pidof was completely rewritten for the inclusion within procps-ng component. This reimplementation brought some behavioral changes, as you may notice.

I took the liberty of lowering the urgency of this bug, as there is a workaround for this issue.
procps-ng component contains a tool 'pgrep' which can provide the same results as pidof and also has some good perks (I suggest to check the manpage), as it can match even substrings of the target program, UIDs, PPIDs, PGIDs etc.

To get results similar to pidof's, try
$ pgrep -f $your_program

TBH I rarely use pidof in favor of pgrep.

Since a convenient workaround exists, I enabled Devel CONDNAK to see if upstream accepts the patch of pidof I sent there.
If it is vital for your usage to have pidof fixed (I would really love to know the use-case, just for statistical knowledge), we can discuss it further.

Enjoy and have a nice day!

Comment 4 Jan Rybar 2020-04-14 10:31:23 UTC
Fix accepted by upstream.

Comment 8 Bryan Hill 2020-06-01 15:39:56 UTC
(In reply to Jan Rybar from comment #3)
> Hello Malahal,
> 
> first, I will explain the pidof's behaviour you're experiencing.
> Pidof in RHEL7 was part of sysvinit-tools component. Since sysvinit-tools
> was abandoned in RHEL8, pidof was completely rewritten for the inclusion
> within procps-ng component. This reimplementation brought some behavioral
> changes, as you may notice.
> 
> I took the liberty of lowering the urgency of this bug, as there is a
> workaround for this issue.
> procps-ng component contains a tool 'pgrep' which can provide the same
> results as pidof and also has some good perks (I suggest to check the
> manpage), as it can match even substrings of the target program, UIDs,
> PPIDs, PGIDs etc.
> 
> To get results similar to pidof's, try
> $ pgrep -f $your_program
> 
> TBH I rarely use pidof in favor of pgrep.
> 
> Since a convenient workaround exists, I enabled Devel CONDNAK to see if
> upstream accepts the patch of pidof I sent there.
> If it is vital for your usage to have pidof fixed (I would really love to
> know the use-case, just for statistical knowledge), we can discuss it
> further.
> 
> Enjoy and have a nice day!


Hello!

I can provide an answer to this, as I was working with Malahal on the issue.  The pidof command, in this particular case, is used by the NFS monitoring script used in the clustered NFS functionality in IBM Spectrum Scale (GPFS).  It looks for pids of nfsd kernel threads and if there are none detected, it shuts the node down.  Since pidof changed, no nfsd pids are returned, and therefore causes causes the node shutdown.  But I see the fix is in QA so that's good news. 

Thanks,
Bryan

Comment 12 errata-xmlrpc 2020-11-04 01:38:34 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (procps-ng bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:4459

Comment 13 Arpit Tolani 2021-05-03 06:43:43 UTC
It is still not working after upgrading to latest package. 

# rpm -q procps-ng
procps-ng-3.3.15-3.el8_3.1.x86_64

# ps aux |grep nfsd
root        7229  0.0  0.1  50132  2392 ?        Ss   09:25   0:00 /usr/sbin/nfsdcld
root       12934  0.0  0.0      0     0 ?        S    09:27   0:00 [nfsd]
root       12938  0.0  0.0      0     0 ?        S    09:27   0:00 [nfsd]
root       12942  0.0  0.0      0     0 ?        S    09:27   0:00 [nfsd]
root       12946  0.0  0.0      0     0 ?        S    09:27   0:00 [nfsd]
root       12947  0.0  0.0      0     0 ?        S    09:27   0:00 [nfsd]
root       12948  0.1  0.0      0     0 ?        S    09:27   0:01 [nfsd]
root       12949  0.4  0.0      0     0 ?        S    09:27   0:03 [nfsd]
root       12950  2.5  0.0      0     0 ?        S    09:27   0:22 [nfsd]
root       44818  0.0  0.0  12112  1020 pts/0    R+   09:41   0:00 grep --color=auto nfsd

# pidof nfsd

# pgrep -f nfsd
7229
12934
12938
12942
12946
12947
12948
12949
12950

Comment 14 Jan Rybar 2021-05-03 07:02:52 UTC
(In reply to Arpit Tolani from comment #13)
> It is still not working after upgrading to latest package. 
> 
> # rpm -q procps-ng
> procps-ng-3.3.15-3.el8_3.1.x86_64
> 
> # ps aux |grep nfsd
> root        7229  0.0  0.1  50132  2392 ?        Ss   09:25   0:00
> /usr/sbin/nfsdcld
> root       12934  0.0  0.0      0     0 ?        S    09:27   0:00 [nfsd]
> root       12938  0.0  0.0      0     0 ?        S    09:27   0:00 [nfsd]
> root       12942  0.0  0.0      0     0 ?        S    09:27   0:00 [nfsd]
> root       12946  0.0  0.0      0     0 ?        S    09:27   0:00 [nfsd]
> root       12947  0.0  0.0      0     0 ?        S    09:27   0:00 [nfsd]
> root       12948  0.1  0.0      0     0 ?        S    09:27   0:01 [nfsd]
> root       12949  0.4  0.0      0     0 ?        S    09:27   0:03 [nfsd]
> root       12950  2.5  0.0      0     0 ?        S    09:27   0:22 [nfsd]
> root       44818  0.0  0.0  12112  1020 pts/0    R+   09:41   0:00 grep
> --color=auto nfsd
> 
> # pidof nfsd
> 
> # pgrep -f nfsd
> 7229
> 12934
> 12938
> 12942
> 12946
> 12947
> 12948
> 12949
> 12950

Hello,

pidof needs to be run with '-x' parameter to show kernel workers.
Implementing this functionality into default behavior would break numerous scripts.

Comment 15 Jan Rybar 2021-05-03 07:03:40 UTC
(In reply to Jan Rybar from comment #14)
> (In reply to Arpit Tolani from comment #13)
> > It is still not working after upgrading to latest package. 
> > 
> > # rpm -q procps-ng
> > procps-ng-3.3.15-3.el8_3.1.x86_64
> > 
> > # ps aux |grep nfsd
> > root        7229  0.0  0.1  50132  2392 ?        Ss   09:25   0:00
> > /usr/sbin/nfsdcld
> > root       12934  0.0  0.0      0     0 ?        S    09:27   0:00 [nfsd]
> > root       12938  0.0  0.0      0     0 ?        S    09:27   0:00 [nfsd]
> > root       12942  0.0  0.0      0     0 ?        S    09:27   0:00 [nfsd]
> > root       12946  0.0  0.0      0     0 ?        S    09:27   0:00 [nfsd]
> > root       12947  0.0  0.0      0     0 ?        S    09:27   0:00 [nfsd]
> > root       12948  0.1  0.0      0     0 ?        S    09:27   0:01 [nfsd]
> > root       12949  0.4  0.0      0     0 ?        S    09:27   0:03 [nfsd]
> > root       12950  2.5  0.0      0     0 ?        S    09:27   0:22 [nfsd]
> > root       44818  0.0  0.0  12112  1020 pts/0    R+   09:41   0:00 grep
> > --color=auto nfsd
> > 
> > # pidof nfsd
> > 
> > # pgrep -f nfsd
> > 7229
> > 12934
> > 12938
> > 12942
> > 12946
> > 12947
> > 12948
> > 12949
> > 12950
> 
> Hello,
> 
> pidof needs to be run with '-x' parameter to show kernel workers.
> Implementing this functionality into default behavior would break numerous
> scripts.

Sorry, '-w' parameter.