Starting Process as Daemon

Hi there,
After a couple of years of not using FreeBSD, I'm finally back! :e If there's one thing I remember, it's the great community!

Well, I'm back with a question, lol.

Is there a way to start a process in the background, but have it still running even when I logout? I tried appending '&' to the end of the command, but the process gets killed when I close my SSH connection.

Thanks guys!
 
Try redirecting all output to a file (i.e. away from the console/login shell) before backgrounding.

[cmd=]some_command > /path/to/somefile 2>&1 &[/cmd]
or
[cmd=]some_command > /dev/null 2>&1 &[/cmd]
(those are for bash)

A more hi-tech solution is, of course, sysutils/screen!
 
Use nohup command to execute commands after you exit from a shell prompt / remote ssh session.
Code:
nohup /path/to/command arg1 arg2 &

The standard output is appended to the file nohup.out in the current directory. If standard error is a terminal, it is directed to the same place as the standard output. See examples:
http://www.cyberciti.biz/tips/nohup-execute-commands-after-you-exit-from-a-shell-prompt.html

You can also use disown command supplied with bash shell. Another option is screen command.
 
One interesting alternative is also to use screen(1) (sysutils/screen). It allows you to detach sessions and reattach to them afterwards.
 
daemon is nice, but I don't think one can re-attach to a session?
 
Back
Top