Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # python3 buscar_procesos.py <nombre>
- import subprocess
- import sys
- # compruebo los argumentos
- if len(sys.argv) != 2:
- sys.exit("Error: ejecute python3 buscar_procesos.py <nombre>")
- proceso = sys.argv[1]
- # ejecuto el comando ps aux
- p = subprocess.run(["ps", "aux"], capture_output=True, encoding="utf-8", text=True).stdout
- p = p.splitlines()
- # elimino los encabezados
- p = p[1:]
- datos = []
- for fila in p:
- if proceso in fila:
- posicion = fila.find(".")
- fila = fila[: posicion-2]
- datos.append(fila.strip())
- # borro el ultimo dato (el de busqueda)
- del datos[-1]
- # imprimo los valores
- if datos:
- for dato in datos:
- print(dato)
- else:
- print(f"No se hallaron procesos {proceso} activos en ejecución")
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement