summaryrefslogtreecommitdiff
path: root/libopie2/opiecore
authormickeyl <mickeyl>2004-01-13 19:51:42 (UTC)
committer mickeyl <mickeyl>2004-01-13 19:51:42 (UTC)
commite117e8427cd8bcd0ab1a74abdc5cd4ab12654194 (patch) (side-by-side diff)
treef013f4f92cceefd20fb519f7e9a4d23f00fadac5 /libopie2/opiecore
parent81b48fa5be4806e3afa64a0d1fa254fbdf9b7315 (diff)
downloadopie-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...
Diffstat (limited to 'libopie2/opiecore') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/oprocess.cpp30
-rw-r--r--libopie2/opiecore/oprocess.h5
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
@@ -36,10 +36,12 @@ _;:,     .>    :=|. This program is free software; you can
/* 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>
@@ -913,3 +915,31 @@ bool OProcess::isExecutable( const QCString &filename )
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
@@ -461,6 +461,11 @@ public:
*/
void detach();
+ /**
+ * @return the PID of @a process, or -1 if the process is not running
+ */
+ static int processPID( const QString& process );
+
signals:
/**