PDA

View Full Version : Check for running applications in linux using Qt



rinku
26th August 2012, 12:24
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.

tbscope
26th August 2012, 13:30
A process is an instance of an application.

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

rinku
27th August 2012, 17:10
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..

spirit
27th August 2012, 17:16
You can use top (http://linux.about.com/od/commands/l/blcmdl1_top.htm) & analyze its output.

Talei
27th August 2012, 18:07
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.

spirit
27th August 2012, 18:28
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.


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.

Talei
28th August 2012, 10:01
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.

spirit
28th August 2012, 10:10
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.



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 ;)

Talei
28th August 2012, 12:19
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 :).