En/na Luiz Americo Pereira Camara ha escrit:
Luca Olivetti wrote:
En/na Luiz Americo Pereira Camara ha escrit:
It's working here both under win32 and linux (testraw and
testcomponent programs). Using fpc 220, Ubuntu Feisty Faw, recent
lazarus svn.
I assure you that I could lauch various copies of my program. I used
fpc 2.0.4, maybe that's the problem. I only used uniqueinstanceraw,
since it's a daemon, not a gui app.
Did you tested the testraw program that comes bundled with the package?
Although it uses a Lazarus app, the pattern usage can be transported to
a non gui app straightforward.
Yes, the testraw program works, but my program forks and using your unit
it allows multiple instances, with mine only one.
Here's a simple program that doesn't work (i.e it allows multiple
instances) if it forks, but it works if left in the foreground (give it
the -f parameter).
This is with fpc 2.0.4. Wait a moment...now I tested with 2.2.0 and
everything works as expected, so it was probably a 2.0.4 thing.
Bye
--
Luca
program test;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, sysutils, strutils, baseunix,
{ add your units here }
uniqueinstanceraw;
var terminated:boolean;
procedure Init;
var
mypid:TPid;
begin
if InstanceRunning('testprogram') then
begin
Writeln('Already running!');
Halt(100);
end;
if paramstr(1)<>'-f' then
begin
mypid:=FpFork;
if mypid<0 then
begin
writeln('fork failed');
halt(mypid);
end;
if mypid>0 then Halt(0); //parent
end;
Close(input);
Close(stderr);
Assign(stderr,'/dev/null');
Rewrite(stderr);
Close(stdout);
Assign(stdout,'/dev/null');
Rewrite(stdout);
end;
procedure CatchSignal(Sig : Longint; Info : PSigInfo; Context : PSigContext);cdecl;
begin
terminated:=true;
end;
procedure InitSignals;
Var
old,new : SigactionRec;
begin
New.sa_handler:[EMAIL PROTECTED];
fpSigaction(SIGQUIT,@New,@Old);
fpSigaction(SIGTERM,@New,@Old);
fpSigaction(SIGINT,@New,@Old);
end;
begin
Init;
InitSignals;
while not terminated do sleep(100);
end.