From: Robert L. <bob...@gm...> - 2012-11-11 19:56:50
|
Hello all, I'd like to know if it is at all possible to write UNIX-like daemons in a MinGW (non-MSYS) environment. Of course I could just go ahead and try to cook something that fork()s off and does its thing in the background, but I'd like to know if it works on Windows just as on Linux. On startup, the program must check if another instance is already running, and must abort. Alternatively, when called a second time with a command-line option, it must cause the existing process to cleanly terminate. Since all the program does is a periodic consistency check of a bunch of files once a minute, writing out the result in another file, it is trivial to just have a batch file call the program in an infinite loop. This is what I'll do for the first testing version. Eventually I would like the thing to run invisibly in the background without littering the task bar with nonsensical command windows though. Thanks, robert |
From: John B. <joh...@ho...> - 2012-11-11 20:31:21
|
On Sun, 11 Nov 2012 20:56:44 +0100, Robert Latest wrote: > > Hello all, > > I'd like to know if it is at all possible to write UNIX-like daemons > in a MinGW (non-MSYS) environment.<snip/> > Thanks, > robert > Hello Robert, Have you considered writing a Windows Service? See:http://msdn.microsoft.com/en-us/library/ms685141(v=vs.85).aspx Regards,John Brown. |
From: Alessandro A. <ant...@gm...> - 2012-11-12 11:17:18
|
2012/11/11 John Brown <joh...@ho...> > On Sun, 11 Nov 2012 20:56:44 +0100, Robert Latest wrote: > > > > Hello all, > > > > I'd like to know if it is at all possible to write UNIX-like daemons > > in a MinGW (non-MSYS) environment. > <snip/> > > Thanks, > > robert > > > > Hello Robert, > > Have you considered writing a Windows Service? See: > http://msdn.microsoft.com/en-us/library/ms685141(v=vs.85).aspx > > Regards, > John Brown. > > > ------------------------------------------------------------------------------ > Everyone hates slow websites. So do we. > Make your web apps faster with AppDynamics > Download AppDynamics Lite for free today: > http://p.sf.net/sfu/appdyn_d2d_nov > _______________________________________________ > MinGW-users mailing list > Min...@li... > > This list observes the Etiquette found at > http://www.mingw.org/Mailing_Lists. > We ask that you be polite and do the same. Disregard for the list > etiquette may cause your account to be moderated. > > _______________________________________________ > You may change your MinGW Account Options or unsubscribe at: > https://lists.sourceforge.net/lists/listinfo/mingw-users > Also: mailto:min...@li...?subject=unsubscribe > Hi, Robert. John is right. There is no such a thing as daemons on Windows. The only way to go is Windows Services. It's painful to implement but works. "fork()" doesn't work outside of Cygwin/Msys environment. The address http://msdn.microsoft.com/en-us/library/ms685141(v=vs.85).aspx That John gave to you is a good start. There is another one http://www.codeproject.com/Articles/16488/A-Windows-Service-Application Tha has some example that you can take as a starting point. Regards, Alessandro |
From: Cristiano S. <sum...@gm...> - 2012-11-13 11:26:53
|
Maybe is trying to say that he needs only one instance running. Inter Process Communication? An alternative if shared memory is available is to write some value at an shared scope. Then each new program instance should check if this global value( magic number ) exists then the second instance should abort or terminate( signal on pthreads? ) the second running program. Write the PID and program name at shared scope and each new instance should check those values are still valid. Your application will write files, so can not you write a pid file? Some socket pipe stuff? |
From: Josue A. G. <jos...@gm...> - 2012-11-13 11:35:15
|
On Tue, Nov 13, 2012 at 9:26 AM, Cristiano Sumariva <sum...@gm...>wrote: > Maybe is trying to say that he needs only one instance running. > > Inter Process Communication? > > An alternative if shared memory is available is to write some value at an > shared scope. > Then each new program instance should check if this global value( magic > number ) exists then the second instance should abort or terminate( signal > on pthreads? ) the second running program. > Write the PID and program name at shared scope and each new instance > should check those values are still valid. > > Your application will write files, so can not you write a pid file? > > Some socket pipe stuff? > > > The canonical way of "one instance only" check on Win32 is to create a named mutex (CreateMutex) and check the error (GetLastError) for ERROR_ALREADY_EXISTS. josue josuegomes.com |
From: Robert L. <bob...@gm...> - 2012-11-14 08:08:35
|
Hello Cristiano, On Tue, Nov 13, 2012 at 12:26 PM, Cristiano Sumariva <sum...@gm...> wrote: > Maybe is trying to say that he needs only one instance running. Yes, I need only one running instance. At any given time there may be only one instance running. > Inter Process Communication? None necessary. No interaction with any other system/process at all. No listening on sockets and stuff (maybe my wording "daemon" is a bit high-fetched for such a program). Just periodically checking stuff on the file system and writing the result out on a protocol file. > Your application will write files, so can not you write a pid file? Yes I can. My current testing version simply runs out of an infinite loop in a batch file. This does the job 100% but bears the risk that somebody accidentally closes that console window, stopping the process. This is why I looked for a more "invisible" solution. Background info: This program is a supervisor which ensures the integrity of so called "recipe files" on a computer that controls an industrial production equipment. The equipment is operated 24/7. Two possible failure scenarios: - The supervisor program compromises the computer and somehow endangers the production process BAD BAD BAD! - The supervisor program just stops working (because, for instance, somebody closes the apparently useless console window). Then the factory automation system will deny the start of the next production run due to an out-of-date integrity protocol file. This happens on a Friday afternoon, you can imagine how happy everybody will be. Maybe I can do something with the Windows "Scheduled Tasks" thing. Need to find out the finest "granularity" of time periods it can do. I'm aiming for one run every minute. Thanks, robert |
From: Konrad H. <ko...@pa...> - 2012-11-14 11:34:54
|
> -----Original Message----- > From: Robert Latest [mailto:bob...@gm...] > Sent: Sunday, November 11, 2012 1:57 PM > To: MinGW Users List > Subject: [Mingw-users] How to write a "proper" Win32 daemon using MinGW? > > Hello all, > > I'd like to know if it is at all possible to write UNIX-like daemons > in a MinGW (non-MSYS) environment. Of course I could just go ahead and > try to cook something that fork()s off and does its thing in the > background, but I'd like to know if it works on Windows just as on > Linux. On startup, the program must check if another instance is > already running, and must abort. Alternatively, when called a second > time with a command-line option, it must cause the existing process to > cleanly terminate. Robert -- I've been watching this thread in anticipation of learning a new trick that I could accomplish with MSys/MinGW that also runs on Linux. Alas, no joy <G>. I have written and compiled several Portable Linux Daemons that also run as Windows Services using Active State's PDK. Starting as a single perl-script which is compiled to a.exe for Windows or an elf binary for Linux, Active State perl is the most portable and 'UNIX-like' method I have yet found (<G> but I am still looking <G>). > Since all the program does is a periodic consistency check of a bunch > of files once a minute, writing out the result in another file, it is > trivial to just have a batch file call the program in an infinite > loop. This is what I'll do for the first testing version. Eventually I > would like the thing to run invisibly in the background without > littering the task bar with nonsensical command windows though. This is something that Perl could do very well. Maybe take a look at perl as included with MSys / MinGW ? If you need to compile the code, Active State Perl is 'one way to do it'. -- kjh(<G> I don't work for Active State, nor do I own any stock <G>) |