w3resource

Python: Start a new process replacing the current process

Python Operating System Services: Exercise-18 with Solution

Write a Python program to start a new process replacing the current process.

Sample Solution:

Python Code :

main.py:

import os
import sys
program = "python"
arguments = ["hello.py"]
print(os.execvp(program, (program,) + tuple(arguments)))
print("Goodbye")

hello.py:

print("Operating System Services Exercises-18")

Sample Output:

Operating System Services Exercises-18

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to run an operating system command using the os module.
Next: Python Operating System Services Home page.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/os/python-os-exercise-18.php