[fpc-pascal] Daemon question

Joost van der Sluis joost at cnoc.nl
Thu May 14 10:55:23 CEST 2009


Op woensdag 13-05-2009 om 22:28 uur [tijdzone +0200], schreef Koenraad
Lelong:
> Hi,
> I wrote a daemon monitoring my solar powerstation. It works fine but I
> want to extend it.
> At the moment I log everything to file, and I put some data into rrdtool.
> I would like to be able to ask the daemon some information, but I don't
> know how to do this.
> I made some signals : sigterm to terminate gracefully, sighup to
> restart, sigusr0 to get the uptime and sigusr1 to get some device-info.
> Except, sigusr0 and sigusr1 use writeln's to output the data which I
> never see when I ask for them (kill -10 <processid>). Where do these
> writeln's write to ? 

If you have 'daemonized' your program properly, these writelines
disappear in an empty void... (As they should)

Or else (if it's not daemonized properly) they would go to the terminal
which was used to start the daemon. And that's not what you want.

The 'daemonize-process' closes the stdout-handle, or re-assigns it
to /dev/null. You could assign it to something else, like a file.

> How can I get that info ? It should be software-independent, because I
> would like to use php to get that information.
> I thought of writing the info to a file, but that info is updated every
> 15 seconds. I think it's not good to write a new file every time.

There's no difference between writing to file and writing to console?

> Now I'm writing this, I could write to a file after receiving a signal,
> and then reading this with php.

You could use IPC. (TSimpleIPCServer) 

> Thinking about it, does php support sending signals ? Back to the books.

And does it support IPC? No idea, but php can call external programs.

Joost.




More information about the fpc-pascal mailing list