Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import subprocess
- should_run=1
- while(should_run):
- x=input("ubos>")
- if(x=="exit"):
- break #breaks the loop when the input command is exit
- else:
- z=x.split(" ") # else the given command must be split based on spaces and loaded into list
- pid=os.fork() # fork is created
- if(pid<0):
- print("Fork Failed") #prints that the fork is failed if obtained pid <0
- if(pid==0):
- subprocess.call(z) #call the execvp and execute the command in the list z
- print("Child Process Created") # prints that the child process is completed
- else:
- os.waitpid(pid,0) #wait till the parent process is completed
- should_run=-1
- print("Parent Process Created")
- break
Add Comment
Please, Sign In to add comment