B
Benoit Dejean
hello, i have a question about forking processes
atm, i have some code which i want to rewrite
os.system("cd ~ && exec " + cmd + " & disown")
i want to remove this os.system call
def fork_exec_disown(cmd, dir="~"):
if os.fork()==0:
os.chdir(os.path.expanduser(dir))
os.setsid()
os.umask(0)
if os.fork():
sys.exit(0)
cmd = cmd.split()
os.execvp(cmd[0], cmd)
but i am not sure that this have the same behaviour.
is the second fork needed ? i think so to detach the spawn process
i have found in the os doc, os.setsid, i think i have to use it.
am i going wrong or is this simple
def fork_exec_disown(cmd, dir="~"):
if os.fork()==0:
os.chdir(os.path.expanduser(dir))
cmd = cmd.split()
os.execvp(cmd[0], cmd)
a good replacement for my os.system call
thank you
atm, i have some code which i want to rewrite
os.system("cd ~ && exec " + cmd + " & disown")
i want to remove this os.system call
def fork_exec_disown(cmd, dir="~"):
if os.fork()==0:
os.chdir(os.path.expanduser(dir))
os.setsid()
os.umask(0)
if os.fork():
sys.exit(0)
cmd = cmd.split()
os.execvp(cmd[0], cmd)
but i am not sure that this have the same behaviour.
is the second fork needed ? i think so to detach the spawn process
i have found in the os doc, os.setsid, i think i have to use it.
am i going wrong or is this simple
def fork_exec_disown(cmd, dir="~"):
if os.fork()==0:
os.chdir(os.path.expanduser(dir))
cmd = cmd.split()
os.execvp(cmd[0], cmd)
a good replacement for my os.system call
thank you