Qt : QProcess get PID
Qt : QProcess get PID
In computing, the process identifier (normally referred to as the process ID or just PID) is a number used by most operating system kernels (such as that of UNIX, Mac OS X or Microsoft Windows) to (temporarily) uniquely identify a process. This number may be used as a parameter in various function calls allowing processes to be manipulated, such as adjusting the process’s priority or killing it altogether (wikipedia).
From this post, I try to write how Qt with QProcess get PID. We can show QProces get PID with use command :
Q_PID QProcess::pid () const
This function will Returns the native process identifier for the running process, if available. If no process is currently running, 0 is returned. This is screenshot my program Qt : QProcess get PID :

From this program, we can type a name of a program and press button ‘Process’. If that program exist, this Qt : QProcess get PID will open that program and show PID from that program. We can check PID from this program from command line/konsole and type :
ps -e
This is a screenshot of my computer from this command :

We can see, PID value from Qt : QProcess get PID is equal with PID from konsole command. You can get the complete source code from Qt : QProcess get PID in here.
Source : http://en.wikipedia.org/wiki/Process_identifier
Hi totosugito,
Thanks for posting this demo. I’d been searching all over for a way to kill a process from within a Qt app and even read an answer to a question on Stackoverflow that “QProcess does not support shell commands”. Well, I see that your demo shows that you can get the PID via a shell command, and I amended the code to also kill an identified process in Debian Wheezy.
Thanks again.