Process Creation
I LOVE DOING THIS :)
Whenever, we execute our python program - it becomes a process and sits in the pstable (process table) in the backend, Irrespective of the operating system
So in this exercise we are going to create a process, within the process (our .py program)
Forking ?
Cloning of an existing process
Forking creates an identical process as the parent process
The execution is duplicated exactly at the point of call to the
fork()
returns 0 in the child process
returns pid (process id) in the parent process
Pid is different for the parent and child process
To explain these confusing topics, I've written a simple program below
We are defining a
child
process first with a print statement returning it's PID usingos.getpid()
And then we are defining the parent process which forks the child using
os.fork()
methodIf the
fork_the_child
variable is equal to zero (Basically, it must be as at the time of fork call the child's process is 0) then it executes the child processElse, it executes the print statement with the forked child's PID
To represent it in the simplest way would be
Last updated