Thanks to Michael and to A.J. for the answers.

To explanation purposes, i'll put the "main project" code at the end of that mail, so you can understand what I done by now and give me tips or alerts.

Of course. KILL is just a signal like any other. You can have various signals :

HUP   commonly this means re-read your config files.
ALRM  Wake-up call :-)
USR1  This can mean whatever you want.
USR2  This can mean whatever you want.
TERM  This means, shut down ASAP. It allows a clean shutdown.
KILL  This just removes the app from memory. Cannot be caught.

All you need to do is set up a signal handler and undertake appropriate action.
In your case, TERM should be caught and allow the application to exit 
gracefully.

Thanks, I supposed that but I didn't find documentation on the wiki on how to catch that signals. I used both killall and kill -9 commands while developing that prototype, istintively sending commands to it, but I didn't knew they could be catched with Lazarus. The demonstration they can is that with the simple killall method the application died itself (with a default hidden Close; event I suppose) , so it can die "cleanly" too.

Where can I found infos about the signals catch?
2) How do I configure threads in linux? I mean... I'd like to change their
name and aspect like other services do, and keep under control their behaviour
(state, resume call times, speed, cpu usage, ecc).

Simply use the TThread methods.

I'll watch them... however control+spacing sometimes don't shows me the methods, and that is an example.
3) Does killing the main_unit (father) kills the processes? I tryed an example
in wich I launch 2 thread before the main closes with the .end and they seem
to "survive", but having the father alive can be useful to control purposes...

I should test this, I don't know.
I tested that:
If you create threads and don't loop the main project, at the "end." the main dies, but the threads continue to live well. However having the main alive can be useful to stop, free, and clean destroy them, so I decided to made a loop (in wich I check the connected state of the various classes and -in case- reconnect them).
4) What does the fpfork command used in the "doing a service under linux"
example on your wiki?
I'm a bit confused about it's behaviour, cause doing an if block with (pid=0)
on it makes the program do both the if and the else in the same time...

fork creates an exact copy of the program. Both parent and child continue
to execute; You can tell whether you're in parent or child by examining
the return value: 0 means you're in the child.
Thanks, so that's probably why I was compiling over the same binary without problems :D
5) How can I access classes istances (or threads) created by their father from
the different childs? I got a lot of recursive declaration errors trying to do
that but I failed to access them with "self.father.class" like calls.

I'm not sure I understand your question. You can access class instances
accross threads without problems ?

Look the code for an explanation... actually I create istances of the classes and I pass the already-created-ones into the "create" of the next ones. That is owful, I'd like to access every istance of a class, using it's father like that:
I'm inside child A=> father.childB.method("command")
Michael.

_________________________________________________________________
     To unsubscribe: mail [EMAIL PROTECTED] with
                "unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives



I'll follow A.J. tip of the /var/run/daemonname.pid file creation, while I wait to see some code that catches the various signals.

Thanks in advance again,
here is the poorly translated code if someone wants to give me some tips:

CODE
////////////////////////////////////////////////////////////////////////////////
program servizio_main;
{$mode objfpc}{$H+}
uses
cthreads,  baseunix,  SysUtils,
servizio_config, servizio_log, servizio_server, servizio_mysql, servizio_client;

var
Config    : TServizio_Config;
Log       : TServizio_Log;
Server    : TServizio_Server;
Mysql     : TServizio_Mysql;
Client    : TServizio_Client;
pid       : Integer;
////////////////////////////////////////////////////////////////////////////////
begin
{$IFDEF unix}
pid:=fpfork;
{$ENDIF}{$IFDEF windows}
pid:=0;
{$ENDIF}

if (pid=0) then begin

  // read the conf file
  Config:= TServizio_Config.Create();

  // start the log flushes
  Log:= TServizio_Log.Create(Config);
  Log.Scrivi('MAIN  > Programma Partito!');  // scrivi = write

  // connect to mysql
  Mysql:= TServizio_Mysql.Create(Config, Log);

// create the thread for the tcp server (that's for visual client purposes, the client is written in delphi only for windows)
  Server:= TServizio_server.Create(Config, Log, Mysql);
  // start the Thread
  Server.Resume;

// create the thread that connect to a tcp client (that's a door to open with an ip address and some commands)
  Client:= TServizio_client.Create(Config, Log, Mysql, Server);
  // start the Thread
  Client.Resume;

  // start the loop (in the future it will be stoppable)
  while (true) do begin
    sleep(5000);

    // if the server wasn't open i reopen it
    if (Server.Quit=True) then Server.Riparti;

    // if the client wasn't connected i connect it again
    if (Client.Connesso=False) then Client.Riconnetti;

    // if the mysql connection wasn't alive i connect it again
    if (Mysql.Connesso=False) then Mysql.Connetti;
  end;
end
end.
////////////////////////////////////////////////////////////////////////////////

NOTE:
actually client and server uses lnet (there on linux) and the client for THAT server is done with indy on windows.
mysql works well with SQLdb
for the configuration file I'm using xml

for the threads I used the base wiki example, extending the demo classes of lnet

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to