Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2007-10

TProcess.Terminate

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Micha Nelissen

Hi,

On unix TProcess.Terminate will send a TERM signal, if this succeeds it will poll if it exited, and immediately send a KILL signal if not. Isn't this a bit rigorous ? It may not have had a change to run even, let alone terminate properly.

Also, it calls GetExitStatus.

Perhaps there should be distinction between 'ask to terminate' and 'kill now' ?

Micha

Reply by email

Michael Van Canneyt
to Micha Nelissen
Micha Nelissen wrote 11 lines
Hi, On unix TProcess.Terminate will send a TERM signal, if this succeeds it will poll if it exited, and immediately send a KILL signal if not. Isn't this a bit rigorous ? It may not have had a change to run even, let alone terminate properly. Also, it calls GetExitStatus. Perhaps there should be distinction between 'ask to terminate' and 'kill now' ?

It's modelled on Windows. There terminate doesn't ask questions. Hence the implementation.

Michael.

Reply by email

Micha Nelissen
to Michael Van Canneyt
Michael Van Canneyt wrote
It's modelled on Windows. There terminate doesn't ask questions. Hence the implementation.

Then it's badly modelled.

There is no way on windows to "cleanly" ask a process to terminate ? Send it a WM_QUIT message or so ?

Micha

Reply by email

Michael Van Canneyt
to Micha Nelissen
Micha Nelissen wrote 8 lines
Michael Van Canneyt wrote: > It's modelled on Windows. There terminate doesn't ask questions. > Hence the implementation. Then it's badly modelled. There is no way on windows to "cleanly" ask a process to terminate ? Send it a WM_QUIT message or so ?

The Terminate call in windows is the equivalent of sending a KILL. So the unix call is even rather 'soft'.

What concerns a WM_QUIT: you need a window handle for this, and you don't have that in e.g. a command-line program or service.

If you want a more 'friendly' way, I think we should add a call 'TryTerminate(Timeout : Integer)' or something, which tries to send a WM_QUIT on windows and which sends a TERM on Linux; after TimeOut milliseconds it should probe to see whether the process actually stopped.

Michael.

Reply by email

Micha Nelissen
to Michael Van Canneyt
Michael Van Canneyt wrote
What concerns a WM_QUIT: you need a window handle for this, and you don't have that in e.g. a command-line program or service.

Perhaps there is a way to query the "main window" for a process, if any ?

Show quoted text 5 lines
If you want a more 'friendly' way, I think we should add a call 'TryTerminate(Timeout : Integer)' or something, which tries to send a WM_QUIT on windows and which sends a TERM on Linux; after TimeOut milliseconds it should probe to see whether the process actually stopped.

Probably you want the call to return as soon as possible, not always after Timeout ? Also, there should be async way, perhaps when Timeout = 0.

Micha

Reply by email

Michael Van Canneyt
to Micha Nelissen
Micha Nelissen wrote 14 lines
Michael Van Canneyt wrote: > What concerns a WM_QUIT: you need a window handle for this, and you > don't have that in e.g. a command-line program or service. Perhaps there is a way to query the "main window" for a process, if any ? > If you want a more 'friendly' way, I think we should add a call > 'TryTerminate(Timeout : Integer)' or something, which tries to send a > WM_QUIT on windows and which sends a TERM on Linux; after TimeOut > milliseconds it should probe to see whether the process > actually stopped. Probably you want the call to return as soon as possible, not always after Timeout ? Also, there should be async way, perhaps when Timeout = 0.

Sure, this is an implementation detail. 0 and -1 can be special values.

Michael.

Reply by email