I have a python code, which has some part that needs to be run on foreground since it tells out if the socket connection was proper or not. Now after running that part the output is written into a file.
Is there a way to move the running python code (process) automatically from foreground to background after running some definite steps in foreground, so that I can continue my work on terminal.
I know using screen
is a option but is there any other way to do so. Since after running a part on foreground, there won't be any output shown in the terminal, I don't want to run screen unnecessarily.
In python, you can detach from the current terminal, note this will only work on UNIX-like systems:
In Bash you can really only do things interactively. When you wish to place the python process into background use CTRL+Z (the leading
$
is the convention for a generic bash prompt):Note that using
setsid()
in the python code will not show the process injobs
, since background job management is done by the shell, not by python.