Understanding the get_process_info() function

As far as functions go, the get_process_info() function, is relatively straightforward and mainly serves to set up the rest of the code execution. On line 166, we create the pid_info dictionary, which is ultimately returned to the calling function on line 336 and contains the extracted process data. Next, using the psutil.pids() method as an iterator, which we showed in the demonstration of this library earlier, we pass each process ID to the get_pid_details() method and store the returned data in the pid_info dictionary, with the PID serving as the dictionary key.

Let's look at the get_pid_details() function next:

158 def get_process_info():
159 """
160 Gather details on running processes within the system.
161 :return pid_info: A dictionary containing details of
162 running processes.
163 """
164
165 # List of PIDs
166 pid_info = {}
167 for pid in psutil.pids():
168 pid_info[pid] = get_pid_details(pid)
169 return pid_info