Comando pidof en Linux con ejemplos

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

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

pisdof-single-pid 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 

bash-pic-root 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

pidof-omit 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

find-and-kill-a-process In this, firstly we find all PIDs of chrome server and then kill it.

Publicación traducida automáticamente

Artículo escrito por khu5h1 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *