Results 1 to 5 of 5

Thread: Determine if a process is running (platform independant)

  1. #1
    Join Date
    Nov 2009
    Location
    Germany
    Posts
    2
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Determine if a process is running (platform independant)

    Hi everyone

    I'm relative new to Qt (but not to programming in C++) and absolutly new to this forum.
    English is not my native language and I hope everyone will understand me

    I read this forum for a few weeks as a guest. I come from Germany and there is a german Qt-forum too, but it's quality is far away from this forum (slime )

    My Qt skills grows day by day and I hope in the future i can help other Qt-ler's too.

    My main-platform is Win32 under Windows XP (and soon on Windows 7 when I get enough time to install and configure it)

    And here is my first question:

    Is there a platform-independant (Qt-like) way to determine if a process is running?
    For example under Win32 a program called testprogram.exe is running - is it possible to determine this without Win32-Api-calls?

    And if not, is it possible for my program to determine on which OS it is running at runtime?
    So that I can use Win32-Api-calls only when it is running on a win32-machine?

    So, enough for my first post. Thanks to all of you who got the time to read this and maybe can help me ...

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Determine if a process is running (platform independant)

    Quote Originally Posted by Arktos View Post
    Is there a platform-independant (Qt-like) way to determine if a process is running?
    I don't know

    And if not, is it possible for my program to determine on which OS it is running at runtime?
    So that I can use Win32-Api-calls only when it is running on a win32-machine?
    Qt Code:
    1. bool isRunning = false;
    2. #ifdef Q_OS_WIN32
    3. // do your windows stuff here
    4. // e.g.
    5. is Running = true;
    6. #endif
    7. #ifdef Q_OS_UNIX
    8. // do your Unix stuff here
    9. #endif
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Lykurg for this useful post:

    Arktos (9th November 2009)

  4. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Determine if a process is running (platform independant)

    Why do you need to know which OS you are running on at runtime? Your going to need two different executables anyway, so might as well do it differently in each, by means of a #ifdef or similar.

  5. The following user says thank you to squidge for this useful post:

    Arktos (9th November 2009)

  6. #4
    Join Date
    Nov 2009
    Location
    Germany
    Posts
    2
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Determine if a process is running (platform independant)

    Thanks to both of you. Of course you are right I have to build for each OS separately, so I can use the Qt-Macros and #IF -Statements anyway.

    But the second part of my question is still interesting for me. Why? I will give you a short background of what i want to do:

    I write a statistic program for a game. This game writes logfiles while playing this game.
    Now it is interesting for my program to know wheter the game is running and when it is running to live-refresh the statistics by reading the logfile.

    The Game runs on Win32 and MacOS, so i ask for a way to determine platform independant that the game ( a process) is running at this moment when my statistic program is running as well.

    Thank you very much for reading
    and have a nice day

  7. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Determine if a process is running (platform independant)

    You mean you want to do inter process communication? Or you could just use a mutex to detect whether or not the first program is running (If its running, trying to acquire the mutex will fail as its already been obtained by the first program).

    Or, you could just do it the way Unix programs have done it for years: Open a file when the first program runs. Write the process id to that file (or something else, for example, the date and time if you don't care about talking to it), and delete that file when the first program quits. The second program (the statistic program) will simply check if that file exists, and if so, will assume the first program is running (and perhaps check the contents to make sure the file isn't stale)

Similar Threads

  1. Determine the Process ID
    By Jimmy2775 in forum General Programming
    Replies: 5
    Last Post: 7th October 2011, 09:16
  2. Connecting with QProcess to an already running process
    By high_flyer in forum Qt Programming
    Replies: 7
    Last Post: 26th November 2007, 10:31
  3. Crash handler on Win32
    By niko in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2007, 19:41
  4. Detect platform where my QT4 program is running on
    By the_bis in forum Qt Programming
    Replies: 1
    Last Post: 14th September 2007, 12:01
  5. Check wheter a process is running
    By Lele in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2006, 12:35

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.