Guest User

Untitled

a guest
Oct 17th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import os
  2. import subprocess
  3. should_run=1
  4. while(should_run):
  5. x=input("ubos>")
  6. if(x=="exit"):
  7. break #breaks the loop when the input command is exit
  8. else:
  9. z=x.split(" ") # else the given command must be split based on spaces and loaded into list
  10. pid=os.fork() # fork is created
  11. if(pid<0):
  12. print("Fork Failed") #prints that the fork is failed if obtained pid <0
  13. if(pid==0):
  14. subprocess.call(z) #call the execvp and execute the command in the list z
  15. print("Child Process Created") # prints that the child process is completed
  16. else:
  17. os.waitpid(pid,0) #wait till the parent process is completed
  18. should_run=-1
  19. print("Parent Process Created")
  20. break
Add Comment
Please, Sign In to add comment