w3resource

Python: Start a new process replacing the current process


18. Replace Current Process

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

For more Practice: Solve these Related Problems:

  • Write a Python program to write a string to an in-memory buffer using io.StringIO, retrieve the value, and then clear the buffer.
  • Write a Python function that writes multiple lines to a buffer, prints the buffer's content, and then discards it by closing the buffer.
  • Write a Python script to simulate file operations on a memory buffer: write data, read it back, and then reset the buffer to an empty state.
  • Write a Python program to use an in-memory buffer to temporarily store text, print the content, and then demonstrate that the buffer is empty after discarding.

Go to:


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

Python Code Editor:

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

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.