# Starting Process as Daemon



## Deacalion (May 12, 2009)

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!


----------



## DutchDaemon (May 12, 2009)

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!


----------



## vivek (May 12, 2009)

Use nohup command to execute commands after you exit from a shell prompt / remote ssh session.

```
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.


----------



## Deacalion (May 13, 2009)

*Thanks!*

Cheers guys! exactly what I was looking for! :e


----------



## roberto@ (May 13, 2009)

One interesting alternative is also to use screen(1) (sysutils/screen).  It allows you to detach sessions and reattach to them afterwards.


----------



## DutchDaemon (May 13, 2009)

That makes _three_ screen recommendations


----------



## tangram (May 13, 2009)

_Four_ here 

Although some people prefer misc/tmux over sysutils/screen.


----------



## ctaranotte (May 13, 2009)

You may want to try misc/dtach


----------



## IncubuS (May 14, 2009)

daemon(8) from base?


----------



## DutchDaemon (May 14, 2009)

daemon is nice, but I don't think one can re-attach to a session?


----------

