# How to make process working in background?



## zhup (Aug 28, 2015)

Hello,

I have below startup script.
My question is how to make this process working in background?


```
#!/bin/sh
. /etc/rc.subr
name=test
rcvar=test_enable
command="/usr/sbin/${name}"
load_rc_config $name
run_rc_command "$1"
```
Why I am not able to stop this process?


```
root@mys:~ # /etc/rc.d/test stop
Stopping test.
Waiting for PIDS: 5146 5147
Waiting for PIDS: 5146 5147
```
Thank you in advance.


----------



## zhup (Aug 29, 2015)

I found solution for the process working in background:

```
command_args="--daemon"
```
How to stop the process?

```
root@mys:~ # /etc/rc.d/test stop
Stopping test.
Waiting for PIDS: 5146 5147
Waiting for PIDS: 5146 5147
```


----------



## hanzer (Sep 3, 2015)

zhup said:


> How to stop the process?


Have you seen the document "Practical rc.d scripting in BSD"?
rc.subr(8) might also be useful.

My first _WAG_ would be to include a line like:

```
pidfile="/var/run/${name}.pid"
```


----------

