PIDOF(8)

๐Ÿ“ฆ
version 3.18 ยท 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

๐ŸŽ€ PIDOF(8) ๐ŸŽ€

Okay bestie, this page is from the Linux System Administrator's Manual and it's all about pidof ๐Ÿ’…


โœจ NAME โœจ

pidof - find the process ID of a running program ๐Ÿ”

๐Ÿ‘€ SYNOPSIS โœจ

pidof [-s] [-c] [-n] [-x] [-z] [-o omitpid[,omitpid...]] [-o
omitpid[,omitpid...]...] [-d sep] program [program...]

๐Ÿ’– DESCRIPTION โœจ

So pidof finds the process IDs (PIDs) of the programs you name and prints those IDs to standard output ๐Ÿ–จ๏ธโœจ It's giving "find me the PID, no cap."

Lowkey, on some systems this gets used in run-level change scripts, especially when the system has a System-V-style rc structure. In that case the scripts live in /etc/rc?.d, where ? is the runlevel ๐Ÿงš If your system has a start-stop-daemon(8) program, that's the one you should be using instead, periodt ๐Ÿ’…

๐ŸŽ€ OPTIONS โœจ

  • -s โ€” Single shot! ๐ŸŽฏ This tells the program to only return one PID, bestie.
  • -c โ€” Only return PIDs of processes running with the same root directory ๐ŸŒธ This one gets ignored for non-root users, because they can't check the current root directory of processes they don't own ๐Ÿ™ˆ
  • -n โ€” Skip the stat(2) system call on all binaries sitting on network-based file systems like NFS ๐ŸŒ Instead of using this flag, you can set and export the variable PIDOF_NETFS ๐Ÿฆ‹
  • -q โ€” Quiet mode ๐Ÿคซ Don't show matched PIDs on standard out. The program just exits with a status of true or false to tell you whether a matching PID was found. Main character energy โœจ
  • -x โ€” Scripts too! ๐Ÿ“œ This makes the program also return the process IDs of shells that are running the named scripts ๐Ÿš
  • -z โ€” Tries to detect processes stuck in zombie (Z) status ๐ŸงŸ Normally these get skipped, because messing with them can make pidof or related tools hang ๐Ÿ’€ Quick tea: back in the day pidof would skip processes in the uninterruptible state (D) unless you passed -z. That's no longer the case! Now pidof finds and reports D state processes whether or not you use -z ๐Ÿซถ
  • -d sep โ€” Tells pidof to use sep as the output separator when more than one PID is shown ๐Ÿ“ The default separator is a space.
  • -o omitpid โ€” Tells pidof to leave out processes with that process ID ๐Ÿ™…โ€โ™€๏ธ The special PID %PPID can be used to name the parent process of the pidof program, aka the calling shell or shell script ๐Ÿ‘‘

๐Ÿ“Š EXIT STATUS โœจ

  • 0 โ€” Yay! At least one program with the requested name was found ๐ŸŽ‰
  • 1 โ€” Oof, no program with the requested name was found ๐Ÿ˜ญ

๐Ÿ“ NOTES โœจ

Okay so pidof is actually the same program as killall5(8). It just behaves based on the name it was called under ๐Ÿงš

When you invoke pidof with the full pathname to the program you want, it's reasonably safe ๐Ÿ”’ Otherwise it's possible it returns PIDs of running programs that just happen to share the same name but are actually different programs. Iykyk ๐Ÿ™ˆ Also, the executable name of running processes is calculated with readlink(2), so symbolic links to executables will match too ๐Ÿฆ‹

Heads up, bestie! Zombie processes and processes in disk sleep (states Z and D, respectively) are ignored by default, because trying to access their stats can sometimes fail ๐Ÿ’€ The -z flag tells pidof to try detecting these sleeping and zombie processes, but it comes with the risk of failing or hanging. Proceed with caution ๐Ÿซฃ

๐Ÿ”— SEE ALSO โœจ

shutdown(8), init(8), halt(8), reboot(8), killall5(8) ๐Ÿ’œ

๐Ÿ‘‘ AUTHOR โœจ

Miquel van Smoorenburg ๐Ÿงš


Okay that's the whole page, bestie ๐ŸŒˆ It's from sysvinit, last updated 01 Sep 1998. Love you, mwah ๐Ÿ˜˜๐Ÿฆ‹๐Ÿ’–

๐Ÿ“ฆ where this page comes from