author | mickeyl <mickeyl> | 2004-01-13 19:51:42 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-01-13 19:51:42 (UTC) |
commit | e117e8427cd8bcd0ab1a74abdc5cd4ab12654194 (patch) (side-by-side diff) | |
tree | f013f4f92cceefd20fb519f7e9a4d23f00fadac5 /libopie2/opiecore | |
parent | 81b48fa5be4806e3afa64a0d1fa254fbdf9b7315 (diff) | |
download | opie-e117e8427cd8bcd0ab1a74abdc5cd4ab12654194.zip opie-e117e8427cd8bcd0ab1a74abdc5cd4ab12654194.tar.gz opie-e117e8427cd8bcd0ab1a74abdc5cd4ab12654194.tar.bz2 |
- add the static method int OProcess::processPID(const QString&)
- add an example program for dealing with OProcess. This should be enhanced...
-rw-r--r-- | libopie2/opiecore/oprocess.cpp | 30 | ||||
-rw-r--r-- | libopie2/opiecore/oprocess.h | 5 |
2 files changed, 35 insertions, 0 deletions
diff --git a/libopie2/opiecore/oprocess.cpp b/libopie2/opiecore/oprocess.cpp index f1a5f3b..5cfcf32 100644 --- a/libopie2/opiecore/oprocess.cpp +++ b/libopie2/opiecore/oprocess.cpp @@ -27,28 +27,30 @@ _;:, .> :=|. This program is free software; you can Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "oprocctrl.h" /* OPIE */ #include <opie2/oprocess.h> /* QT */ #include <qapplication.h> +#include <qdir.h> #include <qfile.h> #include <qmap.h> #include <qregexp.h> #include <qsocketnotifier.h> +#include <qtextstream.h> /* STD */ #include <errno.h> #include <fcntl.h> #include <pwd.h> #include <stdlib.h> #include <signal.h> #include <stdio.h> #include <string.h> #include <sys/time.h> #include <sys/types.h> #include <sys/stat.h> @@ -904,12 +906,40 @@ bool OProcess::isExecutable( const QCString &filename ) { return false; } // CC: now check for permission to execute the file if ( access( filename.data(), X_OK ) != 0 ) return false; // CC: we've passed all the tests... return true; } +int OProcess::processPID( const QString& process ) +{ + QString line; + QDir d = QDir( "/proc" ); + QStringList dirs = d.entryList( QDir::Dirs ); + QStringList::Iterator it; + for ( it = dirs.begin(); it != dirs.end(); ++it ) + { + //qDebug( "next entry: %s", (const char*) *it ); + QFile file( "/proc/"+*it+"/cmdline" ); + file.open( IO_ReadOnly ); + if ( !file.isOpen() ) continue; + QTextStream t( &file ); + line = t.readLine(); + //qDebug( "cmdline = %s", (const char*) line ); + if ( line.contains( process ) ) break; //FIXME: That may find also other process, if the name is not long enough ;) + } + if ( line.contains( process ) ) + { + //qDebug( "found process id #%d", (*it).toInt() ); + return (*it).toInt(); + } + else + { + //qDebug( "process '%s' not found", (const char*) process ); + return -1; + } +} diff --git a/libopie2/opiecore/oprocess.h b/libopie2/opiecore/oprocess.h index 352485b..1a2472d 100644 --- a/libopie2/opiecore/oprocess.h +++ b/libopie2/opiecore/oprocess.h @@ -452,24 +452,29 @@ public: */ static QString quote( const QString &arg ); /** * Detaches OProcess from child process. All communication is closed. * No exit notification is emitted any more for the child process. * Deleting the OProcess will no longer kill the child process. * Note that the current process remains the parent process of the * child process. */ void detach(); + /** + * @return the PID of @a process, or -1 if the process is not running + */ + static int processPID( const QString& process ); + signals: /** * Emitted after the process has terminated when * the process was run in the @p NotifyOnExit (==default option to * @ref start()) or the @ref Block mode. **/ void processExited( OProcess *proc ); /** * Emitted, when output from the child process has |