Getting the PID
of a process by name with and without the sysutils/psmisc
port.
Instructions:
The fallow example uses pgrep
in a bash script file:
The easy way is to install sysutils/psmisc
port and use the pidof
command:
Fallowing command can by used to get information to all of the processes matching a name:
Fallowing command can be used to get the PIDs of all processes matching a name:
Below script can be used to controll flow in a shell script. The -qs
flags supress grep output:
Reference:
- FreeBSD, man pgrep
- How to terminate process by name in UNIX
My site is free of ads and trackers. Was this post helpful to you? Why not