I have taken operating systems for granted but looking internally it's an excellent experience to understand how everything gets glued together, this post will be an overview of a process and what happens to a process.
A program is nothing but a set of instructions that the user writes for the desired behaviour after execution. when the program gets into a running state that's when you have a process which gets created and gets associated with the program, in other words, this is how to program is abstracted by the process.
Let's consider the below python program, we will create some Child processes and Parent processes from the program and see how the underlying operating sees when we execute the program.
You don't have to be a python expert to know what is going on in this program, basically, we can see the python program has an imported OS module and then it calls on fork() operation to create various child processes.
import osdef child():
print('\nA new child', os.getpid())
os._exit(0)def parent():
while True:
newpid = os.fork()
if newpid == 0:
child()
else:
pids = (os.getpid(), newpid)
print("Parent: %d, child: %d\n" % pids)
reply = input("q for quit / c for new fork")
if reply == "c":
continue
else:
breakparent()