Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a python based server which i start from the terminal. This particular instance of the terminal then gives control to the program, and the program uses it as a kind of logging window, until its closed. Is this normal, or should i somehow try to start the program some other way in which it will simply show as an active process? If i close the terminal from which i started the program, the program dies with it.

Thank you

share|improve this question
    
PHP is mentioned in this answer but it applies to Python, too: askubuntu.com/questions/26555/running-php-cli-server/… –  user8290 Sep 22 '12 at 13:34

3 Answers 3

up vote 6 down vote accepted

Turn it to a daemon (service)
daemon --name="yourservicename" --output=log.txt sh yourscript.sh

share|improve this answer

Even old bash is using & for sending processes to background, but there is few other ways too .. but basic two are these :

1.)$~ your_command > outputfile_for_stdout &
        # runs your command in background, giving you only PID so you can exit that process by `kill -9 PID_of_process`
        # & goes at the end of row      


2.)$~ your_command > outputfile_for_stdout 
        # this will run your program normally
        # press  Ctrl + Z then program will pause
   $~ bg
        # now your program is running in background
   $~ fg
        # now your program came back to foreground
3.)you can run terminal window under screen command so it will live until you either kill it or you reboot your machine
   $~ screen
   $~ run_all_your_commands
       # Ctrl + A + D will then detach this screen
   $~ screen -r will reattach it

Some other useful commands :

   $~ jobs
        # will show you all processes running right now, but without PID
   $~ ps
        # will show you all processes for actual terminal window
share|improve this answer
    
Hmmm, i was using command 'top' to view processes till now –  U2ros Sep 23 '12 at 18:19
$ servicename &

Using & causes the program to run in the background, instead of blocking the shell until the program ends.

share|improve this answer
    
No, it doesn't. Eg. dixon@dixon-vaio:~$ nautilus & [1] 11835. It returns process id and you will new shell prompt. Also check this: http://unix.stackexchange.com/questions/3886/difference-between-nohup-disown-an‌​d. –  dixoncx Sep 23 '12 at 13:07
    
I stand corrected. Down vote removed. –  Scott Severance Sep 23 '12 at 17:24

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.