Python: Operating System Services

First, when we talk about operating system we mean the management of computer hardware and software resources and providing common services for computer programs.
 
Python has the power to easily manipulate the system calls, Operating environment, Processes, Timers, Signal handling, Error reporting, etc…
 
Let’s start with the Environment Variables:
 
user = os.environ[’USER’]
 
os.environ[’PATH’] = "/bin:/usr/bin"
 
Working directory
 
os.chdir(path) # Change current working directory
os.getcwd() # Get it
 
Users and groups
 
os.getegid() # Get effective group id
os.geteuid() # Get effective user id
os.getgid() # Get group id
os.getuid() # Get user id
os.setgid(gid) # Set group id
os.setuid(uid) # Set user id
 
Process
 
os.fork() # Create a child process
os.execv(path,args) # Execute a process os.execve(path, args, env)
os.execvp(path, args) # Execute process, use default path os.execvpe(path,args, env)
os.wait([pid)] # Wait for child process
os.waitpid(pid,options) # Wait for change in state of child
os.system(command) # Execute a system command
os._exit(n) # Exit immediately with status n