2

I have written a program which calculates the amount of battery level available in my laptop. I have also defined a threshold value in the program. Whenever the battery level falls below threshold i would like to call another process. I have used system("./invoke.o") where invoke.o is the program that i have to run. I am running a script which runs the battery level checker program for every 5 seconds. Everything is working fine but when i close the bash shell the automatic invocation of invoke.o is not happening. How should i make the invoke.o to be invoked irrespective of whether bash is closed or not??. I am using UBUNTU LINUX

nikhil
  • 8,677
  • 21
  • 54
  • 81
  • 1
    Any of a large number of [other](http://stackoverflow.com/questions/3720439/) [questions](http://stackoverflow.com/questions/3407197/) on [StackOverflow](http://stackoverflow.com/questions/958249/) will provide you with answers about how to daemonize a program. The simplest is to run the program in background with `nohup`, as in `(nohup yourprogam &)`. – Jonathan Leffler Feb 06 '11 at 22:22

3 Answers3

3

Try running it as: nohup ./myscript.sh, where the nohup command allows you to close the shell without terminating the process.

poundifdef
  • 17,354
  • 21
  • 84
  • 128
0

You could run your script as a cron job. This lets cron set up standard input and output for you, reschedule the job, and it will send you email if it fails.

The alternative is to run a script in the background with all input and output, including standard error output, redirected.

While you could make a proper daemon out of your program that kind of effort is probably not necessary.

DigitalRoss
  • 139,415
  • 24
  • 238
  • 326
0
  1. man nohup
  2. man upstart
  3. man 2 setsid (more complex, leads to longer trail of breadcrumbs on daemon launching).
bmargulies
  • 94,623
  • 39
  • 172
  • 299