Daemonize Anything

I hacked together this little C program from this other little c program. Basically acts as an execution wrapper that lets you fork() and detach and run a command in the background with a pidfile and log file for program output. So far I havent had any problems with it… but then I’m not a true C guy so any input is welcomed.


Posted on : Apr 10 2008
Posted under Business, Personal, Random Thoughts, Software Development, cli, linux |

2 People have left comments on this post

Apr 10, 2008 - 11:04:08
Nikolay said:

If you want to redirect all the output of the program to a file, you don’t need to fork yet another process with popen():

freopen( “/path/to/logfile”, “a”, stdout);
freopen( “/path/to/logfile”, “a”, stderr);
exec[l|v]p( command, … );

Thus you can get both stdout and stderr, you don’t spawn another process and you don’t open and close the log file on every 1024 chars. Of course, the error checking was omitted :-)

Apr 21, 2008 - 10:04:46
NuAngel said:

Hey man, it’s Nu!! Are the IRC’s still in one piece anywhere? Lookin’ to get ahold of a few people, Aly, EE, etc…

Stop by and leave a comment on my site (now: WinBreak.com) or just look me on on a messenger service:

AIM: RotatingFlavors
MSN: NuAngel@hotmail.com