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 :


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


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: Write a Python program to find out what the epoch is on a given platform. Also convert a given time in seconds since the epoch.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

Python: Tips of the Day

Python: Unpack a Tuple

>>> items = (0, 'b', 'one', 10,  11, 'zero')
>>> a, b, c, d, e, f = items
>>> print(f)
>>> a, *b, c = items
>>> print(b)
['b', 'one', 10, 11]
>>> *_, a, b = items
>>> print(a)