

If you run the above app.py file, the new file is created called app.txt and inside that krunal is written because I am the user of my computer. Python os system function allows us to run a command in the Python script, just as if I was running it in my shell. The os.getpid returns the process ID of the current process. The os.getuid os module function returns the current process’s user ID or UID, as it is popularly known. It returns the 20. That means the group id of the current process is 20. It returns the real group id of the current process. Print(os.execvp(program, (program,) + tuple(arguments))) Now, write the following code inside the app.py file. Let’s see the following example.Ĭreate one file inside the same folder called mod.py and add the following code. The execvp function is one of the ways to run other commands on the system. It will create a new directory called newDir inside the current folder. If you want to make a new directory type the following code. The getcwd function of the OS module will give us the current directory of the project. The environ is not a function but a process parameter through which we can access the environment variables of the system. This differs based on the underlying Operating System.

The os.name function gives the name of the OS module it imports. Now, let’s see some of the essential functions of os in detail.
