-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_detect.py
More file actions
42 lines (38 loc) · 1.39 KB
/
process_detect.py
File metadata and controls
42 lines (38 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import platform
import subprocess
import datetime
def show_windows_processes():
try:
output = subprocess.check_output("tasklist", shell=True).decode("utf-8", errors="ignore")
lines = output.strip().split('\n')
print("Running processes (Windows):\n")
for line in lines[3:]: # skip headers
parts = line.split()
if len(parts) >= 2:
name = parts[0]
pid = parts[1]
print(f"-> {name} (PID: {pid})")
except Exception as e:
print(f"Error getting process list: {e}")
def show_unix_processes():
try:
output = subprocess.check_output("ps -eo pid,comm", shell=True).decode("utf-8", errors="ignore")
lines = output.strip().split('\n')
print("Running processes (Linux/macOS):\n")
for line in lines[1:]:
parts = line.strip().split(None, 1)
if len(parts) == 2:
pid, name = parts
print(f"-> {name} (PID: {pid})")
except Exception as e:
print(f"Error getting process list: {e}")
def main():
os_name = platform.system().lower()
if "windows" in os_name:
show_windows_processes()
elif "linux" in os_name or "darwin" in os_name:
show_unix_processes()
else:
print("Unsupported operating system.")
if __name__== "__main__":
main()