El comando pidof se utiliza para averiguar los ID de proceso de un programa en ejecución específico. Básicamente es un número de identificación que se asigna automáticamente a cada proceso cuando se crea. Sintaxis:
pidof [options] program1 program2 ... programN
Trabajar con el comando Pidof
1. Para encontrar el pid de cualquier proceso
pidof bash
Use the name of the program as input to the command and command produced bash process ID in the output. 2. To get only one pid of a program
pidof -s bash
By default, pidof displays all pids of named command or program. So to display only one process ID of the program we have to pass “-s” option with it. 3. To get pids of scripts
pidof -x bash
The pidof command does not display pids of shell/perl/python scripts. We use the “-x” option to find the process ids of shells running the named script called bash. 4. To limit output based on the root directory
pidof -c bash
If we want that pidof returns only process ids that are running with the same root directory, we use “-c” command-line option. Note: This option is ignored for non-root users, as they are unable to check the current root directory of processes they do not own. 5. To omit processes
pidof -o 87223 bash
If we want to ignore or omit processes with that process id, we can use pidof command to this. This is useful to ignore calling shell or shell script or specific pid. Here, it says we want to find all pids of bash and omit pid #87223. So, we use the given code for that. 6. To find pid of a program and kill it
p=$(pidof chrome) kill $p
In this, firstly we find all PIDs of chrome server and then kill it.