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:

  1. 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|

    ReplyDelete
  2. 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

    ReplyDelete
  3. 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

    ReplyDelete
  4. 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

    ReplyDelete
  5. 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

    ReplyDelete