Skip to content

Instantly share code, notes, and snippets.

@mouseroot
Created August 24, 2021 11:28
Show Gist options
  • Save mouseroot/15fcccf4c0eef2b237800faa24b29ae0 to your computer and use it in GitHub Desktop.
Save mouseroot/15fcccf4c0eef2b237800faa24b29ae0 to your computer and use it in GitHub Desktop.
import os
def GetPID(processName):
procs = [proc_fd for proc_fd in os.listdir("/proc/") if proc_fd.isdigit()]
for proc_fd in procs:
try:
status_fd = open("/proc/{0}/status".format(proc_fd),"r").readlines()
for line in status_fd:
if "Name:" in line:
name = line.replace("Name:\t","").replace("\n","")
if processName in name:
print("Process ID: {0} - {1}".format(proc_fd,name))
except PermissionError as Perr:
print("Permission Denied!!!")
except IOError as IOerr:
print("IO Error")
inp = input("Process Name: ")
GetPID(inp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment