1

I have the following script under raspbian jessie:

file test.sh contains:

#!/bin/sh -e nohup sleep 321 & sleep 120 false exit 0 

When run as normal user in a terminal session, I have the following situation:

pi@raspberrypi:~ $ ps -ejf |grep sleep pi 5073 5072 5072 4618 0 15:16 pts/1 00:00:00 sleep 321 pi 5074 5072 5072 4618 0 15:16 pts/1 00:00:00 sleep 120 

and after the script exits, the sleep 321 process is reparented and still running as expected.

pi@raspberrypi:~ $ ps -ejf |grep sleep pi 5073 1 5072 4618 0 15:16 pts/1 00:00:00 sleep 321 

Why doesn't this work in rc.local? The command run with nohup gets just killed.

pi@raspberrypi:~ $ ps -ejf |grep sleep root 450 449 449 449 0 15:45 ? 00:00:00 sleep 321 root 451 449 449 449 0 15:45 ? 00:00:00 sleep 120 

and after 120 seconds the sleep 321 process just disappears.

It only works in rc.local when I replace false with false || true, so my guess is, it has something to do with running the script with -e, but why the difference between running test.sh from a terminal and rc.local at boot?

1 Answer 1

1

Because nohup would allow only for SIGHUP ignore. But there's also "session" concept in UNIX processes; typical way to daemonize a process is somewhat way more lengthy than just ignoring SIGHUPs.

As Gene Pavlovsky suggests in his comment: "Take a look at daemonize. Besides a nice tool, it has pretty good explanations on what a daemon is."

— You should indeed.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.