The pidof
command in Bash is used to find the process IDs (PIDs) of running programs. It is particularly useful for identifying the PIDs associated with a specific executable, allowing users to manage processes effectively.
The basic syntax of the pidof
command is as follows:
pidof [options] [arguments]
-o, --exclude
: Exclude specified PIDs from the output.-s, --single
: Return only a single PID for the specified program.-q, --quiet
: Suppress output; return exit status only.Here are some practical examples of using the pidof
command:
pidof firefox
pidof firefox chrome
pidof -o 1234 firefox
pidof -s apache2
pidof -q ssh
pidof
in scripts to dynamically manage processes based on their PIDs.pidof
with other commands like kill
to terminate processes easily. For example:
kill $(pidof firefox)
pidof
returns nothing if the specified program is not running, which can be useful for conditional checks in scripts.