23 December 2017

Process Management in Python - os.exec

This is continuation of the previous post - Process Management in Python - os.fork()

In Linux, running a command from the shell is a two-step process. The shell first creates a process using fork (posted earlier) and overlays a new program using "exec". For example, when you want to run the command "ls" from the shell - the shell forks a copy of its own and immediately loads the binary of "ls" and starts the execution again.


Beware, you cannot find a function exec() but rather it is a family of functions with names such as - execl, execle, execlp, execv. The functions are almost same and they differ only in parameters that are being passed. I have used one such functions in the following code. When you run this code, you should see a directory listing - the current process upon the successful calling of exec, loads "ls" and executes it. Once "ls" is executed, it exits (like it normally used to do)

As an experiment, you can do fork to create a child process and in the child process execution flow, you can overlay a new program.

Refer the Code in GIT Hub

Try running this script from Linux shell and see the output. Do not forget to share, like, comment if you like this post :-)


7 comments:

rose said...

Some us know all relating to the compelling medium you present powerful steps on this blog and therefore strongly encourage contribution from other ones on this subject while our own child is truly discovering a great deal. Have fun with the remaining portion of the year.

python training in bangalore|

Keerthana said...

I have gain a lot of information's from your Articles and Looking For more Posts...Thanks for this Information's about Python
python training in chennai | python training in annanagar | python training in omr | python training in porur | python training in tambaram | python training in velachery

saran said...

Brilliant article. The information I have been searching precisely. It helped me a lot, thanks. Keep coming with more such informative article. Would love to follow them.
Digital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery

tech said...

Free download Adobe InCopy 2022 v17.4.0.51 full version standalone offline installer for Windows PC, authors and editors can stylize text, track changes and .Adobe InCopy 2022 Full

syedhaseeb said...

Open HitmanPro.Alert · Click on the red or green icon in the bottom right corner · Click on Activate license · Enter your product key, including hyphens · Click . Hitman Pro Serial Number

haseeb said...

I love you and can't wait to see you; may this magical Christmas night be full of miracles. I hope Santa brings you all the gift of eternal joy.Christmas Wishes For Girlfriend

Syedhaseebulhassan said...

A nakiri knife has a rectangular blade and is mostly used for chopping vegetables whereas a santoku knife is more like an all purpose, traditionally shaped.Use Of Nakiria