Recent

Author Topic: [SOLVED] Process.Terminate(0); not working  (Read 1447 times)

petevick

  • Sr. Member
  • ****
  • Posts: 374
[SOLVED] Process.Terminate(0); not working
« on: May 19, 2024, 01:04:46 pm »
The Process.Terminate(0) is not closing the app that was executed by Process in Linux, it only terminates the process, but it works fine in Windows. Is there another method for closing an app that was executed by a TProcess ??
« Last Edit: May 20, 2024, 05:48:11 pm by petevick »
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

Thaddy

  • Hero Member
  • *****
  • Posts: 14800
  • Censorship about opinions does not belong here.
Re: Process.Terminate(0); not working
« Reply #1 on: May 19, 2024, 05:08:15 pm »
What works fine in Windows? You asked it to terminate, so it obliges...  also on Linux.
bitrate is always calculated like this:sample rate * bitdepth * number of channels.

petevick

  • Sr. Member
  • ****
  • Posts: 374
Re: Process.Terminate(0); not working
« Reply #2 on: May 19, 2024, 06:04:57 pm »
What works fine in Windows? You asked it to terminate, so it obliges...  also on Linux.
That's my point, Process.Terminate(0) DOESN'T work in Linux, the app remains open....
The Process.Terminate(0) is not closing the app that was executed by Process in Linux, it only terminates the process, ........
....it could be that the app is not responding to Terminate in Linux, but it does in Windows.
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

petevick

  • Sr. Member
  • ****
  • Posts: 374
Re: Process.Terminate(0); not working
« Reply #3 on: May 20, 2024, 09:29:04 am »
It would appear that not all applications respond to the Process.Terminate(0) method in Linux, I've tried several third party apps, FreeFileSync does not respond, neither does Qcad (the app that I'm dealing with), but Meld does respond, all the system apps such as xed do respond.
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

MarkMLl

  • Hero Member
  • *****
  • Posts: 6862
Re: Process.Terminate(0); not working
« Reply #4 on: May 20, 2024, 10:07:15 am »
It would appear that not all applications respond to the Process.Terminate(0) method in Linux, I've tried several third party apps, FreeFileSync does not respond, neither does Qcad (the app that I'm dealing with), but Meld does respond, all the system apps such as xed do respond.

What is it actually doing? This might be the difference between a kill and term signal... if in doubt try using another TProcess to invoke killall (or a targeted kill if you know the PID).

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

petevick

  • Sr. Member
  • ****
  • Posts: 374
Re: Process.Terminate(0); not working
« Reply #5 on: May 20, 2024, 11:06:16 am »
What is it actually doing? This might be the difference between a kill and term signal... if in doubt try using another TProcess to invoke killall (or a targeted kill if you know the PID).

MarkMLl
It's doing nothing, I can execute the app using TProcess.Execute, the app fires up and displays, when I issue Process.Terminate(0) the process is terminated but the app remains open. I've tried a targeted kill, same result, the app remains open.
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

MarkMLl

  • Hero Member
  • *****
  • Posts: 6862
Re: Process.Terminate(0); not working
« Reply #6 on: May 20, 2024, 11:21:34 am »
It's doing nothing, I can execute the app using TProcess.Execute, the app fires up and displays, when I issue Process.Terminate(0) the process is terminated but the app remains open. I've tried a targeted kill, same result, the app remains open.

In that case either you're killing it wrong, or your system's broken.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

TRon

  • Hero Member
  • *****
  • Posts: 2783
Re: [SOLVED] Process.Terminate(0); not working
« Reply #7 on: May 20, 2024, 12:10:15 pm »
The Process.Terminate(0) is not closing the app that was executed by Process in Linux, it only terminates the process, but it works fine in Windows.
Windows works completely different than Linux in that regards so that is not a valid comparison.

What app exactly does not seem to obey the Linux signal handling ?

Code: Pascal  [Select][+][-]
  1. Function TProcess.Terminate(AExitCode : Integer) : Boolean;
  2.  
  3. begin
  4.   Result:=False;
  5.   Result:=fpkill(Handle,SIGTERM)=0;
  6.   If Result then
  7.     begin
  8.     If Running then
  9.       Result:=fpkill(Handle,SIGKILL)=0;
  10.     end;
  11.   { the fact that the signal has been sent does not
  12.     mean that the process has already handled the
  13.     signal -> wait instead of calling getexitstatus }
  14.   if Result then
  15.     WaitOnExit;
  16. end;
  17.  

edit: I just noticed this thread being marked as solved. so this reply seem to be redundant. Still would like to know what the issue was though  :)
« Last Edit: May 20, 2024, 12:12:23 pm by TRon »

petevick

  • Sr. Member
  • ****
  • Posts: 374
Re: [SOLVED] Process.Terminate(0); not working
« Reply #8 on: May 20, 2024, 12:23:47 pm »
The Process.Terminate(0) is not closing the app that was executed by Process in Linux, it only terminates the process, but it works fine in Windows.
Windows works completely different than Linux in that regards so that is not a valid comparison.

What app exactly does not seem to obey the Linux signal handling ?

Code: Pascal  [Select][+][-]
  1. Function TProcess.Terminate(AExitCode : Integer) : Boolean;
  2.  
  3. begin
  4.   Result:=False;
  5.   Result:=fpkill(Handle,SIGTERM)=0;
  6.   If Result then
  7.     begin
  8.     If Running then
  9.       Result:=fpkill(Handle,SIGKILL)=0;
  10.     end;
  11.   { the fact that the signal has been sent does not
  12.     mean that the process has already handled the
  13.     signal -> wait instead of calling getexitstatus }
  14.   if Result then
  15.     WaitOnExit;
  16. end;
  17.  

edit: I just noticed this thread being marked as solved. so this reply seem to be redundant. Still would like to know what the issue was though  :)
I've just removed '[SOLVED]'

The app is called Qcad, I've also tried FreeFileSync which also refuses to die. Other apps like xed die without any argument. This is why I marked as [SOLVED] as I believe it to be a particularity of the app rather than a fault with with Lazarus.

I'm using.....
Code: Pascal  [Select][+][-]
  1.     fpKill(Proc.ProcessID, SIGKILL);
  2.     Proc.WaitOnExit();
  3.  
....to kill the app but the app remains displayed.
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

TRon

  • Hero Member
  • *****
  • Posts: 2783
Re: [SOLVED] Process.Terminate(0); not working
« Reply #9 on: May 20, 2024, 12:40:50 pm »
The app is called Qcad, I've also tried FreeFileSync which also refuses to die. Other apps like xed die without any argument. This is why I marked as [SOLVED] as I believe it to be a particularity of the app rather than a fault with with Lazarus.
In principle it is indeed not he fault of Lazarus rather that of the application not obeying the rules as agreed upon. I find it remarkable as both apps you mentio0ned seem to be pure c-applications (so there is no excuses whatsoever).

Quote
I'm using.....
Yeah that should work though depending on the app a sigterm might work better.

How do these apps behave when you try to kill them using system tools ?, see also here

MarkMLl

  • Hero Member
  • *****
  • Posts: 6862
Re: [SOLVED] Process.Terminate(0); not working
« Reply #10 on: May 20, 2024, 12:49:10 pm »
The app is called Qcad, I've also tried FreeFileSync which also refuses to die. Other apps like xed die without any argument. This is why I marked as [SOLVED] as I believe it to be a particularity of the app rather than a fault with with Lazarus.

What does ps tell you? What happens if you use kill from the shell? With -KILL? With -TERM?

Stop fossicking around with TProcess for the moment, since what you've probably got is a wrapper (possibly a shell script) which is what your program has actually started, which in turn starts off a binary without explicitly giving you a PID etc.

A killed process CANNOT keep running. The kill could fail because you didn't have adequate privilege or the process could be moved to a zombie state. And that's basically what I meant by my "you're killing it wrong" quip: you need to sort out how Qcad is running- i.e. shell-level work- before you have a hope of doing it from inside your program (even with a kill or a killall, for which you need the pid or true name respectively).

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

petevick

  • Sr. Member
  • ****
  • Posts: 374
Re: [SOLVED] Process.Terminate(0); not working
« Reply #11 on: May 20, 2024, 12:51:35 pm »
[How do these apps behave when you try to kill them using system tools ?, see also here
I've tried sigterm, same result  :(
I've just tried capturing the ProcessID which was 26715, and then entered 'kill 26715' in the terminal, the command ran without error, but Qcad reamined displayed. I'll check out your link next.
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

TRon

  • Hero Member
  • *****
  • Posts: 2783
Re: Process.Terminate(0); not working
« Reply #12 on: May 20, 2024, 12:58:22 pm »
@petevick:
The link basically tells what MarkMLI is suggesting.

It slipped my mind but indeed it is quite possible the system runs the app using a 3th party launcher (solution) in which case things work differently/unexpected.

Just try to obtain all the information from a terminal and use the same terminal (or suggested tools in the posted link), e.g. what MarkMLI also suggested to be able to tell if behaviour differs.

petevick

  • Sr. Member
  • ****
  • Posts: 374
Re: Process.Terminate(0); not working
« Reply #13 on: May 20, 2024, 01:07:17 pm »
@petevick:
The link basically tells what MarkMLI is suggesting.

It slipped my mind but indeed it is quite possible the system runs the app using a 3th party launcher (solution) in which case things work differently/unexpected.

Just try to obtain all the information from a terminal and use the same terminal (or suggested tools in the posted link), e.g. what MarkMLI also suggested to be able to tell if behaviour differs.
Yes, I'm beginning to understand what's happening now. Qcad does indeed run from a launcher. I've used ps -A in terminal and qcad and qcad-bin are listed, using the PID for qcad-bin, the kill command does finally kill Qcad.
Pete Vickerstaff
Linux Mint 21.2 Cinnamon, Windows 10, Lazarus 3.2, FPC 3.2.2

TRon

  • Hero Member
  • *****
  • Posts: 2783
Re: Process.Terminate(0); not working
« Reply #14 on: May 20, 2024, 01:20:07 pm »
Yes, I'm beginning to understand what's happening now. Qcad does indeed run from a launcher. I've used ps -A in terminal and qcad and qcad-bin are listed, using the PID for qcad-bin, the kill command does finally kill Qcad.
There you go  :) .

MarkMLI was a bit more focused than I was... Now the question becomes what you want to do about it and what you can do about it (depending on the purpose of your application/tprocess launcher)

I have to admit that is a bit cloudy for me as well.... e.g.  I do not know if there is an universal way to be able to always kill everything some initial process launched.

 

TinyPortal © 2005-2018