In python, you can disconnect from the current terminal by noticing that this will only work on UNIX-like systems:
value = raw_input("Please enter a value: ")
import os
pid = os.fork()
if pid == 0:
os.setsid()
print "In background:", os.getpid()
else:
print "In foreground:", os.getpid()
exit()
In Bash, you really can only do things interactively. If you want to put the python process in the background, use CTRL + Z (the lead $is a symbol for the general Bash hint):
$ python gash.py
Please enter a value: jjj
^Z
[1]+ Stopped python gash.py
$ bg
[1]+ python gash.py &
$ jobs
[1]+ Running python gash.py &
Note that using setsid()python in the code will not show the process in jobs, since the background job is controlled by the shell, not python.
source
share