PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Background process with no wait... INVOKE?  (Read 1080 times)

Cedric

  • Silver Member
  • ***
  • Posts: 25
    • View Profile
Background process with no wait... INVOKE?
« on: October 22, 2021, 08:23:10 AM »
Hi,

I`m looking to improve a function we have that searchs for products via 3 different APIs...  Right now, everything is synchronous, so was looking for a way to go asynchronous to launch 3 queries at the same time and use some sort of data control record to flag when all 3 process are done.  I was trying to use INVOKE in a linux environment where I thought it was creating a new process and executing the command without waiting for the response?

It seems to work pretty much the same as SYS() except I don't receive the response code from OS?  The main process seems to wait until the invoke command is done processing to continue its process...I thought that maybe I had to set param IW to 0, but that didn't do anything!


So, my question is:

Is there a way to execute a background process so that our main process doesn't wait for that background process to finish in linux?  Worst case, I guess I could use a linux shell script... Note that this function could be executed in a WindX session or directly on the server (web queries).

keith.mcbride

  • Member
  • **
  • Posts: 12
    • View Profile
Re: Background process with no wait... INVOKE?
« Reply #1 on: October 22, 2021, 08:34:48 AM »
In Linux if you add an & to the end of  the command line it will run in the background and returning control immediately.
You can INVOKE your existing command, adding a  " &" on the end and it should return control right away.
That should allow you to start all the processes asynchronously

Mike King

  • Diamond Member
  • *****
  • Posts: 3810
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Background process with no wait... INVOKE?
« Reply #2 on: October 22, 2021, 09:55:56 AM »
Cedric

You might also want to consider using Pipes.  This will launch background processes and allow your main thread to continue to run.  You could even return the actual "found" items in the pipe itself.
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

Cedric

  • Silver Member
  • ***
  • Posts: 25
    • View Profile
Re: Background process with no wait... INVOKE?
« Reply #3 on: October 22, 2021, 12:24:14 PM »
Ok, thanks Keith and Mike...  I'll try it out... It makes perfect sense, just thought the INVOKE method existed for that purpose but I guess I misread the documentation.

Thank you

Mike King

  • Diamond Member
  • *****
  • Posts: 3810
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Background process with no wait... INVOKE?
« Reply #4 on: October 22, 2021, 02:29:09 PM »
Technically the INVOKE can be used to spawn a process, however on Unix/Linux it defaults to wait for the process so that an error branch can be taken should the invoke fail.
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com