Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to run commands from the terminal (mostly Python servers) and essentially daemonize them. I am running the MinGW terminal "Git Bash" that comes with the Windows installer for Git.

Things tried that do not work:

  • nohup -> command not found
  • setsid -> command not found
  • $ script.py & -> does not behave as expected
  • $ script.py & disown -> does not behave as expected

I would use bg, but my end-goal is to close the terminal after my servers are all running and not kill the processes.

share|improve this question

2 Answers 2

I have no idea if this will work in bash in Windows, but bash provides a built-in command to "disown" a background process. After you've backgrounded the job with bg just run disown. By default it will disown the most recently bg-ed job, but you can also give it a job number if you have multiple background jobs.

More info here on Job control built-ins.

share|improve this answer
    
Thank you, but like I stated in the original post, disown doesn't seem to be behaving as expected. Clearly, the problem is the Windows bash terminal; I was just hoping there were alternative ways to do this that I could try. –  burfl May 28 '13 at 18:10

This is a synthesis from my longer answer to a similar question in SO.

If your app logs to stdout/stderr, use:

cmd //c start cmd //k  "path\\to\\script-dir\\script.py"

If it logs to files, via sockets etc. and you do not need stdout/stderr, use:

cmd //c start //D "path\\to\\script-dir" script.py

In both cases you get a daemon like process which will survive when you close bash. In the first instance your script is hosted in a visible cmd.exe window.

Much more here.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.