I have a program that runs indefinitely. I which to run this program remotely by issuing the following command:

nohup mono program.exe &

Although I'm able to close the terminal and still have program.exe running, I would like nohup to return me the command prompt ($), so that I can issue more commands before terminating.

How do I go about doing this?


Answer (or workaround)

Do an explicit redirection of the standard output and errors streams

nohup mono program.exe >> nohup.out 2>&1 &

If you execute the command in the way described above, you will get back the command prompt.

You are executing it in the background. So, you should get back the command prompt before terminating the process program.exe. This is not the case!!!?

| improve this answer | |
  • Agreed, as long as you have "&" it should return you to the prompt. Perhaps Mystic is running this from something other than a normal terminal window? It doesn't sound like it though... Mystic? More information please? – Sean Reifschneider Nov 30 '10 at 8:57
  • Based on what I thought should have happened, I agree that I probably should have gotten the prompt. My program busy-waits (with 1 second sleeps) on the main thread. It doesn't block on input from the terminal. I doubt if that is causing the problem, or is it? – Mystic Nov 30 '10 at 10:10
  • @Mystic: Just try this: "$ nohup sleep 20 &". You should get the prompt without waiting for 20 seconds. Your application execution should behave in a similar way! – Khaled Nov 30 '10 at 10:20
  • Tried that using both putty and the ssh client that comes with Cygwin. Neither works. I need to hit the return key in order to see the prompt. Any ideas? – Mystic Dec 1 '10 at 3:55
  • 1
    Alright, I figured this out. I had to do an explicit redirection of the standard out and error streams, i.e, nohup mono program.exe >> nohup.out 2>&1 &. Interesting don't you think? Btw, is nohup available on most Linux distributions? – Mystic Dec 2 '10 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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