Linux command
pidof 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Example
pidof bash
Example
pidof -s bash
Example
pidof -x script.py
Kill
kill $(pidof name)
Example
pidof -t process_name
说明
pidof finds the process IDs (PIDs) of the named programs and prints them on standard output. It is useful for scripting and identifying running processes by name.
参数
- -s
- Single shot - only return one PID
- -c
- Only return process IDs running with the same root directory
- -q
- Quiet mode - suppress output and only set exit status
- -w
- Show processes without visible command line (e.g., kernel threads)
- -x
- Also return PIDs of shells running the named scripts
- -o omitpid
- Omit processes with the specified PID; use %PPID for parent process
- -t
- Show thread IDs instead of PIDs
- -S separator
- Use specified separator between PIDs (default is space)
FAQ
What is the pidof command used for?
pidof finds the process IDs (PIDs) of the named programs and prints them on standard output. It is useful for scripting and identifying running processes by name.
How do I run a basic pidof example?
Run `pidof bash` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -s do in pidof?
Single shot - only return one PID