Recent

Author Topic: Tprocess.Suspend Resume  (Read 2520 times)

sporer@sctn.de

  • New Member
  • *
  • Posts: 24
Tprocess.Suspend Resume
« on: January 18, 2019, 07:16:33 pm »
Good evening,

I want to execute a Tprocess once, and then suspend and resume it repeatedly.

Some pseudo code like that:

- Initialization of TProcess
- Tprocess.Execute followed immediately by TProcess.Suspend
- sleep(1000)
- Tprocess.Resume
- sleep(1000)
- Tprocess.Suspend
- ....... and so on...

All this is nice and easy, but I need to know during program execution whether the TProcess is in the "suspended state" or in the "resumed" state.
TProcess.Running is always TRUE (suspended or resumed).

All this is on a Raspberry PI with Raspbian Jessy and and FPC 2.6.4
When I use "top -i" the process is always turned on and off by resume/suspend

My question is whether it is possible to find out more about the suspend/resumed state.
Thank you, if anyone can help.

Regards


marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Tprocess.Suspend Resume
« Reply #1 on: January 18, 2019, 10:16:50 pm »
What do you expect the tprocess suspend/resume actually does? IOW what do you want to achieve?

(and no, suspend/resume is probably not it)


lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Tprocess.Suspend Resume
« Reply #2 on: January 18, 2019, 10:56:42 pm »
TProcess.Running is useful only to determine whether a process has terminated. A suspended/resumed process is not "terminated" so Running returns True as a matter of course. As the documentation says (somewhat criptically, IMHO):

Quote
Suspend suspends a running process. If the call is successful, the process is suspended: it stops running, but can be made to execute again using the Resume call.

Suspend is fundamentally different from TProcess.Terminate which actually stops the process.

To get the actual state of a process you'll have to use a system-dependent call.
« Last Edit: January 18, 2019, 11:13:30 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Tprocess.Suspend Resume
« Reply #3 on: January 19, 2019, 02:24:52 am »
What do you expect the tprocess suspend/resume actually does? IOW what do you want to achieve?

(and no, suspend/resume is probably not it)

Agreed.  Unless you are writing your own debugger, suspending/resuming is a very bad idea, especially if it is an app you don't have control over.  Do you have the source code for the app?  If so, creating an inter-process communication channel between your main app and the spawned app would be much safer.  Let the main app notify the spawned app when to "suspend" its processing of data without actually suspending the process itself, and then notify again when you want it to "resume" processing.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Tprocess.Suspend Resume
« Reply #4 on: January 19, 2019, 02:25:40 am »
What do you expect the tprocess suspend/resume actually does? IOW what do you want to achieve?

(and no, suspend/resume is probably not it)

Agreed.  Unless you are writing your own debugger, suspending/resuming a process/thread is a very bad idea, especially if you don't have control over it.  You don't know what state it is in at the time of the suspend, what resources it may have locked, etc.

Do you have the source code for the spawned app?  If so, creating an inter-process communication channel between your main app and the spawned app would be much safer.  Let the main app notify the spawned app when to "suspend" its processing of data without actually suspending the process itself, and then notify again when you want it to "resume" processing.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

bytebites

  • Hero Member
  • *****
  • Posts: 633
Re: Tprocess.Suspend Resume
« Reply #5 on: January 19, 2019, 08:33:12 am »

sporer@sctn.de

  • New Member
  • *
  • Posts: 24
Re: Tprocess.Suspend Resume
« Reply #6 on: January 19, 2019, 09:51:13 am »
What do you expect the tprocess suspend/resume actually does? IOW what do you want to achieve?

(and no, suspend/resume is probably not it)

Agreed.  Unless you are writing your own debugger, suspending/resuming is a very bad idea, especially if it is an app you don't have control over.  Do you have the source code for the app?  If so, creating an inter-process communication channel between your main app and the spawned app would be much safer.  Let the main app notify the spawned app when to "suspend" its processing of data without actually suspending the process itself, and then notify again when you want it to "resume" processing.

The reason why I want to use suspend/resume is this:
-using TProcess.Execute / TProcess.Terminate has the effect that with Execute the spawned app needs some few milliseconds to initialize (actually it is a VoIP streaming app, I don't have control over it) which means that there is a short time gap before the VoIP stream starts.
- using Suspend / Resume, the VoIP stream starts immediately.
- question: what exactly is Suspend / Resume doing? I suppose it halts the execution at any point of the code and then continues at the same position in the code, like in an IDE debugging session with breakpoints? Am I right?
- My solution should be either to use Execute / Terminate repeatedly and to accept the time gap (which actually is not a big deal)
- Or to keep track of the Suspend / Resume state with a variable in the main app.  But as you mentionned above, this might have unknown side effects for the spawned app.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Tprocess.Suspend Resume
« Reply #7 on: January 20, 2019, 12:57:46 am »
- question: what exactly is Suspend / Resume doing? I suppose it halts the execution at any point of the code and then continues at the same position in the code, like in an IDE debugging session with breakpoints? Am I right?

Yes, exactly.

- My solution should be either to use Execute / Terminate repeatedly and to accept the time gap (which actually is not a big deal)

Yes, that is the only option for an app you don't have control over.

- Or to keep track of the Suspend / Resume state with a variable in the main app.  But as you mentionned above, this might have unknown side effects for the spawned app.

Of course, you can track when you call Suspend/Resume, but you won't know the state of the app while it is suspended. Or even know when it is safe to suspend it.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Tprocess.Suspend Resume
« Reply #8 on: January 20, 2019, 03:11:35 pm »
Normally apps like that "VoiP" have COM interface abilities, wouldn't it be better to interface it that way?
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018