Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Check if an application is running
QtWS25 Last Chance

Check if an application is running

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 9.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Heryon
    wrote on last edited by
    #1

    Hi, i've searched a lot on the internet, but I didn't find any solution to my problem. I'm making kind of a launcher for some applications. I would want to know, when I start my program, if the app it should run when I click on a button (let's say Firefox) is already launched. I tried various things with QProcess but it didn't seem to work.

    A 2 Replies Last reply
    0
    • M Offline
      M Offline
      Matt86
      wrote on last edited by
      #2

      This is probably OS dependent. If you are working on windows, see the below link.

      http://stackoverflow.com/questions/13657455/how-to-know-if-a-process-is-running-in-windows-in-c-winapi

      1 Reply Last reply
      2
      • H Heryon

        Hi, i've searched a lot on the internet, but I didn't find any solution to my problem. I'm making kind of a launcher for some applications. I would want to know, when I start my program, if the app it should run when I click on a button (let's say Firefox) is already launched. I tried various things with QProcess but it didn't seem to work.

        A Offline
        A Offline
        ambershark
        wrote on last edited by
        #3

        @Heryon Yea I don't know of anything in Qt to do that. You will have to write platform specific code for each OS you support. It's quite easy on windows and linux, and probably on OSX although I haven't done it on OSX. But since it's a posix OS it should be as easy as linux.

        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

        1 Reply Last reply
        1
        • H Offline
          H Offline
          Heryon
          wrote on last edited by
          #4

          Ok thank you, I'll try that.

          R 1 Reply Last reply
          0
          • H Heryon

            Ok thank you, I'll try that.

            R Offline
            R Offline
            rturrentine
            wrote on last edited by
            #5

            @Heryon Do you want to do this on Windows or Linux or a combination of operating systems?

            The basic approach is to search the list of active processes for your executable.

            For Windows use:
            tasklist /fo csv /nh

            For Linux use:
            ps axco pid,command

            You would need to parse the results correctly for the particular OS.

            1 Reply Last reply
            0
            • H Heryon

              Hi, i've searched a lot on the internet, but I didn't find any solution to my problem. I'm making kind of a launcher for some applications. I would want to know, when I start my program, if the app it should run when I click on a button (let's say Firefox) is already launched. I tried various things with QProcess but it didn't seem to work.

              A Offline
              A Offline
              ambershark
              wrote on last edited by
              #6

              @Heryon For windows you can use this api call https://msdn.microsoft.com/en-us/library/windows/desktop/ms682623(v=vs.85).aspx.

              And for linux I would recommend going straight to /proc rather than using ps. Using ps is fine, don't get me wrong, it's just having to allocate and run another process rather than just using the filesystem. Takes a lot more resources and time. There are open source libraries to help you read /proc if you don't want to do it yourself. Something like http://procps.sourceforge.net. I've never used that, just the first thing I found in google.

              My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

              1 Reply Last reply
              2

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved