Recent

Author Topic: [Solved] Stopping a TProcess  (Read 6061 times)

gilsonalencar

  • New Member
  • *
  • Posts: 48
[Solved] Stopping a TProcess
« on: November 02, 2013, 01:19:45 am »
Hi Folks,

Any idea how to stop a tcpdump application initiated by a TProcess.Executable? TProcess.Terminate(0) doesn't work.
« Last Edit: November 06, 2013, 02:57:27 am by gilsonalencar »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Stopping a TProcess
« Reply #1 on: November 02, 2013, 05:24:04 am »
The safe way: Kill using its PID
Easy way: Call .Free

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Stopping a TProcess
« Reply #2 on: November 02, 2013, 05:46:19 am »
According to Tcpdump's website:

Tcpdump will, ... , continue capturing packets until it is interrupted by a SIGINT signal (generated, for example, by typing your interrupt character, typically control-C)

For Windows use GenerateConsoleCtrlEvent(CTRL_C_EVENT, ..

Different OS, take a look at the source code of the debugger's InterruptTarget proc

Code: Text  [Select][+][-]
  1.   TGDBMIDebugger = class(TCmdLineDebugger)
  2.     procedure InterruptTarget; virtual;
  3.  

gilsonalencar

  • New Member
  • *
  • Posts: 48
Re: Stopping a TProcess
« Reply #3 on: November 02, 2013, 05:49:40 pm »
I have already read somethings about uses of PID. But, i didn't understand yet how to do it. The tcpdump stop to run under control+c command. I have been working with Linux and a simple call to TProcess.Free appears doesn't work too.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Stopping a TProcess
« Reply #4 on: November 02, 2013, 07:58:50 pm »
I would suggest using:

Code: Pascal  [Select][+][-]
  1. uses
  2.  ..., BaseUnix;
  3. ...
  4. FpKill(TargetPID, SIGINT);
  5.  

I learned about it from the debugger's InterruptTarget proc

Code: Text  [Select][+][-]
  1. {$IFDEF UNIX}
  2.   FpKill(TargetPID, SIGINT);
  3. {$ENDIF}        
  4.  



gilsonalencar

  • New Member
  • *
  • Posts: 48
Re: [Solved] Stopping a TProcess
« Reply #5 on: November 06, 2013, 03:02:53 am »
Thanks engkin.

The running process stopped with:

FpKill (TProcess.processID, SIGINT);

 

TinyPortal © 2005-2018