Is there a way to query the state of processes in a Linux process table to be able to demonstrate if a process is running or blocked at the time the query is executed? My goal is to do this from 'outside' the process or program, as I hope to understand this in terms of the OS process, but any thought are welcome!
Here is the python code blocked process:
import subprocess
proc = subprocess.call('ls -lRa /', shell=True)
Here is the python code for a non-blocked process:
import subprocess
proc = subprocess.Popen('ls -lRa /', shell=True)
Here is the output of the 'ps -ef' showing the process ids:
UID PID PPID C STIME TTY TIME CMD
user1 14308 4145 0 15:30 pts/2 00:00:00 python call_b.py
user1 14309 14308 0 15:30 pts/2 00:00:00 /bin/sh -c ls -lRa /
user1 14310 14309 15 15:30 pts/2 00:00:30 ls -lRa /
root 14313 2 0 15:31 ? 00:00:00 [kworker/2:0]
user1 14318 2476 0 15:32 pts/4 00:00:00 -bash
user1 14442 1 0 15:33 pts/4 00:00:00 /bin/sh -c ls -lRa /
user1 14443 14442 6 15:33 pts/4 00:00:01 ls -lRa /
While these 'ls' commands are processing, I'd like to show which processes are blocking and which states the others are in. The question is intended to be a tool going forward, for learning about states as I learn multiprocessing with python, so while I believe PID 14309 to be blocking and PID 14442 to be non-blocking, although I may have that wrong. That is why it would be helpful for me to be able to see or test this for all of the PIDs shown.
Thanks to the venerable user 'ubuntu' and their response to this: Blocking and Non Blocking subprocess calls for providing the starter code.
The OS in this case is Ubuntu, but any debian or OS comment would be helpful.