Annotation of mozptch/linux_system.pas, revision 1.2

1.1       oertel      1: unit linux_system;
                      2: 
                      3: //http://rick-ross.com/papers/borcon2001/6204.html
1.2     ! oertel      4: //linkill from
        !             5: // Written for "Kylix Power Solutions" 
        !             6: // Copyright (c) 2001, Coriolis Group Books
1.1       oertel      7: 
                      8: 
                      9: interface
                     10: {$IFDEF LINUX}
1.2     ! oertel     11: uses Classes, libc, SysUtils, fork_exec, ProcStuff;
1.1       oertel     12: // forward definition
                     13: 
1.2     ! oertel     14: procedure linStart(cmdline : string);
        !            15: function start(commandline : string) : boolean;
        !            16: procedure linKill(name : string);
1.1       oertel     17: {$ENDIF}
                     18: 
                     19: implementation
                     20: {$IFDEF LINUX}
                     21: 
                     22: 
                     23: 
                     24: 
                     25: //Using the Classes - A Simple OO Shell
                     26: 
                     27: //Now that the TForker and TExecuter classes have been created, lets re-write the simple shell example.
                     28: 
1.2     ! oertel     29: procedure linStart(cmdline : string);
1.1       oertel     30: var
                     31:   cmd     : string;
                     32:   f       : TForker;
                     33: 
                     34:   procedure ParseArgs(commandline : string; var cmd : string;
                     35:                       strlst : TStrings);
                     36:   var
                     37:     tmp    : string;
                     38:     i      : integer;
                     39: 
                     40:   begin
                     41:     // start with an empty parameter list
                     42:     strlst.Clear;
                     43: 
                     44:     tmp := commandline;
                     45:     i   := Pos(' ',tmp);
                     46:     while (i > 0) do
                     47:     begin
                     48:       // found an argument
                     49:       // extract the string from 1 to i-1
                     50:       strlst.Add(  Copy(tmp,1,(i-1)) );
                     51: 
                     52:       tmp := Copy(tmp,i+1,length(tmp));
                     53:       i   := Pos(' ',tmp);
                     54:     end;
                     55: 
                     56:     if (tmp <> '') then
                     57:     begin
                     58:       // found an argument
                     59:       // extract the string from 1 to len
                     60:       strlst.Add( Copy(tmp,1,length(tmp)) );
                     61:     end;
                     62: 
                     63:     // now get the command from the first argument
                     64:     cmd := strlst.Strings[0];
                     65: 
                     66:     // and delete the first parameter
                     67:     strlst.Delete(0);
                     68:   end; // ParseArgs
                     69: 
                     70: begin
                     71:   // create the forker object
                     72:   f := TForker.Create;
                     73:   f.Exec := TExecuter.Create;
                     74:   f.WaitForChild := true;
                     75: 
                     76: 
                     77:   // search for arguments in the string
                     78:   ParseArgs(cmdline, cmd, f.Exec.Parameters);
                     79:   f.Exec.ProcessName := cmd;
                     80:   f.DoFork;
                     81: end;
1.2     ! oertel     82: 
        !            83: function start(commandline : string) : boolean;
        !            84: begin
        !            85:  linStart(commandline);
        !            86:  start := true;
        !            87: end;
        !            88: 
        !            89: procedure linKill(name : string);
        !            90: var
        !            91:  i : Integer;
        !            92:  L : TList;
        !            93:  PRec : PProcInfoRec;
        !            94: begin
        !            95:  L := GetProcessListByName(name);
        !            96:  if L.Count > 0
        !            97:   then for i := 0 to L.Count - 1 do
        !            98:    begin
        !            99:     PRec := L.Items[i];
        !           100:     with PRec^ do
        !           101:     (*
        !           102:      if MessageDlg('Kill Process ',
        !           103:          'Process ' + IntToStr(i + 1) + ' of ' + IntToStr(L.Count)
        !           104:           + LF + LF
        !           105:          + 'Kill this process?' + LF + LF
        !           106:          + 'Process ID: ' + IntToStr(PID) + LF
        !           107:          + 'Status: ' + Status + LF
        !           108:          + 'User name: ' + UName + LF
        !           109:          + 'Command: ' + CmdName + LF,
        !           110:          mtConfirmation, [mbYes, mbNo], 0) = mrYes
        !           111:      then *)
        !           112:      kill(PID, SIGTERM);
        !           113:    end; { for }
        !           114:    //else ShowMessage('No matches found for ' + PROCESSNAME);
        !           115:  L.Free;
        !           116: end;
        !           117: 
1.1       oertel    118: {$ENDIF}
                    119: end.

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>