I'm trying to control a python based program (which doesn't detach itself from console)



case $1 in
        /sbin/start-stop-daemon --start -b --oknodo --user "$user" --name "$name" --pidfile "$pid" --startas "$prog" --chuid nobody -- --daemon
        /sbin/start-stop-daemon --stop --oknodo --user "$user" --name "$name" --pidfile "$pid" --retry=TERM/5/KILL/1

The start part works fine. I can see the script up and running, but the stop part doesn't. It simply says No xx found running; none killed.

So I guess there's something wrong with the start part?


start-stop-daemon --start --pidfile "$pid" doesn't write to the pid file unless --make-pidfile (-m) is specified. Without --make-pidfile it is up to the program being launched to create it. Also for --make-pidfile to work, the process being launched can't daemonize itself (via a fork), as then start-stop-daemon won't know what PID it should put in the file.

The only thing --pidfile "$pid" does in your usage scenario is that it will result in start-stop-daemon not starting the program if it is already running.

If process still is not stopping, all the criteria passed to start-stop-daemon --stop must match. Meaning $pid has to be a running process, the UID of the process has to match $user, and the process name (arg0) has to match $name.
You can determine the value of arg0 by doing ps h -p $pid -o comm

  • Okay the pidfile is written. But stop part still not functioning, same error message – daisy Jun 17 '14 at 2:20
  • @warl0ck is the pid file correct, and does the UID of the process match $user? – Patrick Jun 17 '14 at 2:22
  • Yes, I saw start-stop-daemon tried to read /proc/pid/stat: read(4, "5559 (python) S 1 5558 5558 0 -1"..., 1024) = 326, so the name should be python instead perhaps? – daisy Jun 17 '14 at 2:24
  • Done, substituted name to python and it worked ;-P – daisy Jun 17 '14 at 2:25
  • Right, yes, $name has to match too. Completely missed that you were passing that in. Will update the answer. – Patrick Jun 17 '14 at 2:29

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.