Diffstat (limited to 'libopie2/opiecore/oprocess.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiecore/oprocess.cpp | 30 |
1 files changed, 30 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 @@ -38,2 +38,3 @@ _;:, .> :=|. This program is free software; you can #include <qapplication.h> +#include <qdir.h> #include <qfile.h> @@ -42,2 +43,3 @@ _;:, .> :=|. This program is free software; you can #include <qsocketnotifier.h> +#include <qtextstream.h> @@ -915 +917,29 @@ bool OProcess::isExecutable( const QCString &filename ) +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; + } +} |