Created
August 24, 2021 11:28
-
-
Save mouseroot/15fcccf4c0eef2b237800faa24b29ae0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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