-
Notifications
You must be signed in to change notification settings - Fork 0
/
output_system_info.py
47 lines (38 loc) · 1.43 KB
/
output_system_info.py
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
43
44
45
46
47
# outputs the system information for where the code block executes
#
import os
import platform
def get_system_info():
# Get system information using os.uname()
uname_info = os.uname()
# Get kernel version using platform.release()
kernel_version = platform.release()
# Get user ID, group ID, process ID, and parent process ID
user_id = os.getuid()
group_id = os.getgid()
process_id = os.getpid()
parent_process_id = os.getppid()
# Get CPU count
cpu_count = os.cpu_count()
# Get system load (1 min, 5 min, 15 min)
system_load_1, system_load_5, system_load_15 = os.getloadavg()
# Concatenate the information with carriage returns
system_info = (
f"System Name: {uname_info.sysname}\n"
f"Node Name: {uname_info.nodename}\n"
f"Release: {uname_info.release}\n"
f"Version: {uname_info.version}\n"
f"Machine: {uname_info.machine}\n"
f"Kernel Version: {kernel_version}\n"
f"User ID: {user_id}\n"
f"Group ID: {group_id}\n"
f"Process ID: {process_id}\n"
f"Parent Process ID: {parent_process_id}\n"
f"CPU Count: {cpu_count}\n"
f"System Load (1 min): {system_load_1}\n"
f"System Load (5 min): {system_load_5}\n"
f"System Load (15 min): {system_load_15}"
)
return system_info
# Print the concatenated system information with carriage returns
output = (get_system_info())