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.
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?
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..
Re: Check for running applications in linux using Qt
You can use top & analyze its output.
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.
Re: Check for running applications in linux using Qt
Quote:
Originally Posted by
Talei
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
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.
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.
Re: Check for running applications in linux using Qt
Quote:
Originally Posted by
Talei
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
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 ;)
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 :).