Checking if a certain app is already running

Need to check and see if an application is running (like firefox) before I run a shell.execute “firefox” command in my app.
I do not want it running twice. Anyway of doing this? I’m in Ubuntu 12.04 Gnome3.

Does FolderItem.Launch also run it twice?

Well, technically, shell.execute will not run a program (such as libreoffice) twice. If it’s running, it’ll just bring that window’s focus to the front. However in the example, as above (firefox) it will bring the window in focus AND open a second, third & forth tab within Firefox. What I’d like to do is my code to test if Firefox is currently running, and if so Terminate it and run again, a new, fresh copy. (for security reasons protecting the currently loaded web page from being viewed)

Sorry. I didn’t explain properly.

Xojo does not built-in ways to check if apps are running. You can maybe query the OS about that. On Linux, I perhaps a shell that calls “ps” looking for the firefox process would work. You’d check the results to see if it was found. Then maybe you could do another shell command to kill the process?

Good idea. Thanks.
Only problem is that the s.execute results only lists the FIRST line, " PID TTY TIME CMD"
In order to check and see if firefox is running, I need to be able to read the second line returning from the ps command. Then I can take proper action. The pc command from the command line works fine. Just need to get that 2nd line data…

BTW. I’m in mode 1.

You’ll probably want to subclass the Shell and then get the data from the DataAvailable event handler.

Paul, I changed mode from 1 to 0 and it now works. I just use an inStr test to look for firefox. Thanks.

Any thoughts on how to “safely” terminate firefox within Real Studio?
I could use:
myshell.Execute “kill -9 PID”

Is there a better way, as to not mess up firefox at all?

Also, after closing firefox and doing a ps, I get a firefox listing, which as you can imagine if now tough to tell if it’s actually running or not.

It’s like the buffer is the ps commad doesn’t get cleared until my Real Studio app ends. then all if fine. Real Studio sorta “locks” firefox in until it closes (my app I mean)

Got it working perfectly. Adding the -f switch to the ps command allows me to see if it is new, or has been run & closed.
Thanks