Results 1 to 9 of 9

Thread: Check for running applications in linux using Qt

  1. #1
    Join Date
    Aug 2012
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Check for running applications in linux using Qt

    I am trying to write an application in Qt which should tell me the currently running applications(not the processes) in my linux system..Actually my application will check in the system whether any application is running or not if it found that there is no any application running then it will do something. plz help.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Check for running applications in linux using Qt

    A process is an instance of an application.

    What do you mean when you say application? Only processes that have a graphical user interface?

  3. #3
    Join Date
    Aug 2012
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Check for running applications in linux using Qt

    i am saying about the currently running applications in your linux system like(mozilla, vlc plyer, doc file etc) how do my application comes to know about those processes are running or not..

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Check for running applications in linux using Qt

    You can use top & analyze its output.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Check for running applications in linux using Qt

    Don't use systems apps, because:
    1. app can be not installed (I doubt that, in this case, top is not present in major distros but it can happen)
    2. top can be "some other malicious software" and when You execute it it will have your app privileges

    Use procfs (/proc). It's present in most (virtually every) kernel, including android kernels.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Check for running applications in linux using Qt

    Quote Originally Posted by Talei View Post
    Don't use systems apps, because:
    1. app can be not installed (I doubt that, in this case, top is not present in major distros but it can happen)

    I've never met situation when I had to install top.
    Quote Originally Posted by Talei View Post
    2. top can be "some other malicious software" and when You execute it it will have your app privileges
    Use procfs (/proc). It's present in most (virtually every) kernel, including android kernels.
    For mac /proc doesn't work (at least out-of-box). So, top or ps -A make life simpler.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Check for running applications in linux using Qt

    Yes these tools are always there for me to.

    On Windows there is no /proc also.
    On the MacOsX is sysctl with is better then parsing /proc (and strictly speaking MacOSX is not Linux it's Unix - question was regarding Linux).

    IMHO on Linux I would go with parsing the /proc(fs), safer.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  8. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Check for running applications in linux using Qt

    Quote Originally Posted by Talei View Post
    Yes these tools are always there for me to.

    On Windows there is no /proc also.
    On the MacOsX is sysctl with is better then parsing /proc (and strictly speaking MacOSX is not Linux it's Unix - question was regarding Linux).
    That's right.

    Quote Originally Posted by Talei View Post
    IMHO on Linux I would go with parsing the /proc(fs), safer.
    I totally agree with you point, but I think it's gonna be hard to implement for topic-starter
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. #9
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Check for running applications in linux using Qt

    IMHO reading /proc is easier, for example (pseudo code, not correct but gives the basic idea):

    Read /proc: QFile().open(fileName) -> QByteArray ba = QFile().readAll(); -> parse(ba);
    Process: QProcess().start(FileName/command) -> slot ReadyRead() -> QByteArray ba = QProcess().readAll(); -> parse(ba);

    Reading /proc don't involve signal/slot mechanism (and, to clarify here, I don't take into account blocking QProcess() because that's just bad programming IMHO, for this problem at least).

    And with blocking QPRocess: QProcess().start(command) -> QProcess().waitForFinished() -> QByteArray ba = QProcess().readAll();. Same as reading /proc.

    Maybe this will help topic starter to get basic idea about possibilities (practically he already has ready solution).

    EDIT:
    I forgot actual parsing and with correct command parsing would be reduced to splitting by the new line, so indeed that would be easier to manage/implement .
    Last edited by Talei; 28th August 2012 at 12:33.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

Similar Threads

  1. Replies: 0
    Last Post: 13th February 2012, 06:44
  2. Replies: 5
    Last Post: 22nd May 2011, 22:38
  3. Problems running applications .exe
    By croussou in forum Installation and Deployment
    Replies: 8
    Last Post: 25th March 2011, 18:07
  4. Running Qt applications on windows
    By Maluko_Da_Tola in forum Newbie
    Replies: 2
    Last Post: 12th September 2010, 20:51
  5. running external applications via QT?
    By cruisx in forum Newbie
    Replies: 1
    Last Post: 11th August 2009, 06:34

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
  •  
Qt is a trademark of The Qt Company.