summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/oprocess.cpp
Side-by-side diff
Diffstat (limited to 'libopie2/opiecore/oprocess.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/oprocess.cpp30
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
@@ -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;
+ }
+}