TL;DR: grep
is wrong tool, use find
with correct options
If you do stat /var/run
you'll quickly find out that /var/run
is symlink to /run
directory.
$ stat /var/run
File: /var/run -> /run
Size: 4 Blocks: 0 IO Block: 4096 symbolic link
Device: 801h/2049d Inode: 696874 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2018-02-07 13:17:01.225178554 +0800
Modify: 2017-12-18 20:44:12.898113636 +0800
Change: 2017-12-18 20:44:12.898113636 +0800
So you really need /run
directory instead. As for searching files with specific filename, you need find
command:
$ find /run -name "*.pid"
/run/charon.pid
/run/starter.charon.pid
/run/dhclient-wlp2s0.pid
Because some files in that directory belong to root or other system users, you may need to use that command with sudo
.
Alternatively, you can use -L
flag to allow following symlinks and call find
on /var/run
:
$ find -L /var/run -name "*.pid"
/var/run/charon.pid
/var/run/starter.charon.pid
/var/run/dhclient-wlp2s0.pid
Please note also, that grep
is wrong tool for the job. grep
is for searching text patterns inside text files, not in their filenames.
You also mentioned:
/var/run stores the processes running in the system and it has files with pid extension
That's actually incorrect. Process information belongs in /proc
. The .pid
files are simply used by some programs to prevent multiple copies of same process running (well, one of possible ways these files can be used). See this stackoverflow post for reference, as well as this highly voted answer on unix.se. While the directory belongs to root user, please don't assume that it's for startup and daemon apps only; scripts initiated with root permissions by user could write to the directory just as easily.
/var/run
. At best you are labouring under the misapprehension that PID files are a necessity, when in fact they are a dangerous and deeply flawed mechanism that the world is at oh-so-long last finally learning the wisdom of getting rid of. – JdeBP Feb 07 '18 at 06:39