Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace current process with invocation of subprocess?

In python, is there a way to invoke a new process in, hand it the same context, such as standard IO streams, close the current process, and give control to the invoked process? This would effectively 'replace' the process.

I have a program whose behavior I want to repeat. However, it uses a third-party library, and it seems that the only way that I can truly kill threads invoked by that library is to exit() my python process.

Plus, it seems like it could help manage memory.

like image 904
eacousineau Avatar asked Jul 19 '11 07:07

eacousineau


1 Answers

You may be interested in os.execv() and friends:

These functions all execute a new program, replacing the current process; they do not return. On Unix, the new executable is loaded into the current process, and will have the same process id as the caller. Errors will be reported as OSError exceptions.

like image 91
detly Avatar answered Sep 20 '22 12:09

detly