For Linux/Mac, use Kill or KillAll: https://www.online-tech-tips.com/computer-tips/kill-program-using-command-line/
Title: Re: Terminate an Executing Program using another QB64 program
Post by: MLambert on May 20, 2019, 07:08:11 pm
How do I obtain the PID ?
Title: Re: Terminate an Executing Program using another QB64 program
Post by: Pete on May 20, 2019, 09:02:15 pm
If you are using Windows, just look up the name of the app in with Windows Task. Find it in the "Process" tab and highlight it. Next, right click, and select "Go to details" In details, you will see the name of the file, and the next column shows the PID.
Now the process ID is something that changes each time a program runs, so if you want to go that route, you will need a remote lookup method. I figured out how to get that yesterday, but only for the QB64 app. Anyway, I'll combine that lookup procedure with taskkill in this next example...
That will make a file tmp.tmp in your local QB64 directory that the code will open in Notepad. It will show you a list of all handle image names and process IDs, etc. YOu can taylor the output with switches, as seen in this resource: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/tasklist
You might be able to incorporate that in your program to find and shutdown a particular process.
Pete
Title: Re: Terminate an Executing Program using another QB64 program
Post by: MLambert on May 21, 2019, 06:33:18 am
Thank you ..
Title: Re: Terminate an Executing Program using another QB64 program
Post by: Pete on May 21, 2019, 09:27:03 am
Depending on the operation, terminating by PID can be a very complex issue. For instance, let's say I have three of the same paint.net programs running. They all have the same image name, but different PIDs. I only want to terminate the second one. So, how do I do that? Well, I can't use the image name, because it would close all three, so hey, I'll terminate by PID, instead! Well, which PID? Why, the second one, of course! Ah, but how do I determine which one is the second one? Well, if task list creates a time ordered list, that would not be a problem, but if it doesn't, things get pretty open for bad results, even with additional programming of a QB64 app running in the background to try to add a time stamp to that task list. So, I'd have to test out has task list orders the list of processes running, and hope it is by time. If not, more work to do.
So, I'm not sure what you are trying to achieve here, simple termination by image name, or you need the PID for a more complex issue, as discussed above. There may be alternative solutions, too. I just don't know of any at the moment. At any rate, no, this cannot be done natively in QB64, much like keeping a window persistent can't be done natively, either. Frankly, if it wasn't for SHELL, I would have pitched QBasic back in the 1990's. It at least made it possible to achieve some of the things that were impossible in native QB. Unfortunately, it was just too daunting a task for Rob to make all those SHELL functions, Windows API functions, which can be done with libraries, native to QB64. I'm just assuming he could have, if he had the time, help, and energy.
Pete
Title: Re: Terminate an Executing Program using another QB64 program
Post by: Raven_Singularity on May 23, 2019, 03:01:38 pm
If they're your apps, you could set the title to something unique.
Title: Re: Terminate an Executing Program using another QB64 program
Post by: MLambert on May 26, 2019, 02:57:12 am