You are not logged in.

#1 2012-06-27 13:01:47

hauptmech
Member
Registered: 2011-12-24
Posts: 4

[SOLVED] rc.local killing forked processes

I'm trying to use rc.local to start a collection of processes that do stuff in the background. These processes set up network sockets for inter process communication, monitor some devices, and output to stdio/stderr and via syslog.

I can fork these processes from a bash shell and they work fine (ie 'myprog &'). However when I try to start them from rc.local, they don't work fine... they startup as expected but then seem to be killed as rc.local exits.

I thought there might be a problem because of the IO and redirected it to /dev/null ('myprog &> /dev/null &') but that didn't help.

Anyone have any ideas on how to fix this? How do I start a process from rc.local that doesn't get killed when rc.local exits?

Thanks,

hauptmech

Last edited by hauptmech (2012-06-27 14:01:16)

Offline

#2 2012-06-27 13:07:19

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,648
Website

Re: [SOLVED] rc.local killing forked processes

man nohup

edit: OK, that's not actually the best man page.  Point is do:

nohup myprog &

so your program does not get killed when it's parent process, rc.local, ends.

Last edited by Trilby (2012-06-27 13:08:39)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2012-06-27 14:15:41

hauptmech
Member
Registered: 2011-12-24
Posts: 4

Re: [SOLVED] rc.local killing forked processes

@tribly thanks for the nohup suggestion but it was not the solution

I was able to diagnose the problem by redirecting stderr/stdout of every process to /tmp/errorfile
'myprog &> /tmp/error.myprog &'

The problem was that the socket based inter-process communication component required the $HOME environment variable which doesn't exist in rc.local. Each process was dumping a helpful error message on STDOUT which of course was not caught by any terminal.

'export $HOME=/home/dummyuser'   solved my problem.

Offline

Board footer

Powered by FluxBB