Recent

Author Topic: [SOLVED] TProcess Termination  (Read 5636 times)

RegNatarajan

  • New Member
  • *
  • Posts: 28
[SOLVED] TProcess Termination
« on: April 27, 2014, 01:37:58 am »
I'm writing a CLI application using FPC that will run in Linux.  I'm just writing it in Vim, not Lazarus.  This application runs another app using TProcess. 

What I want to know is, if my app gets terminated with a ctrl-c, can I count on the TProcess execution to be terminated, too, or do I need to code for that? 

If I do need to code for it, can someone point me to a way to catch a termination event?
« Last Edit: April 29, 2014, 05:58:41 am by skalogryz »

Yogi

  • New Member
  • *
  • Posts: 42
Lazarus 1.3 SVN 44197 * FPC 2.7.1 SVN 26822
Linux: 3.2.0-4-686-pae * Debian wheezy
Windows: W98

RegNatarajan

  • New Member
  • *
  • Posts: 28
Re: TProcess Termination
« Reply #2 on: April 28, 2014, 03:13:21 am »
Maybe I'm missing something but I don't see anything in that link that answers my question.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: TProcess Termination
« Reply #3 on: April 28, 2014, 04:34:21 am »
I don't think that terminating the launching application will terminate any processes ran by it (using TProcess).
Thus you'd need to write additional code to catch "ctrl-c" signal and terminate all child processes manually.

 

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: TProcess Termination
« Reply #4 on: April 28, 2014, 05:43:26 am »
To catch Ctrl+C, I believe, you need to install a handler for SIGINT using FpSignal or FpSigAction.

RegNatarajan

  • New Member
  • *
  • Posts: 28
Re: TProcess Termination
« Reply #5 on: April 29, 2014, 04:13:15 am »
Thanks for this.  I did just that, trapped for ctrl-c in my event loop.  I found some code using the crt unit online (no link, sorry, just googled it and didn't save the link) and it works fine.  Not sure how to mark this question solved but it is.

Code: [Select]
        //Check for ctrl-c
        if KeyPressed then          //  <--- CRT function to test key press
        if ReadKey = ^C then        // read the key pressed
        begin
            TCPDumpProcess.Terminate(0);
            TCPDumpProcess.Free;
            writeln('Ctrl-C pressed.');
            exit;
        end;     

 

TinyPortal © 2005-2018