summaryrefslogtreecommitdiff
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
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 (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/examples/opiecore/opiecore.pro2
-rw-r--r--libopie2/examples/opiecore/oprocessdemo/.cvsignore6
-rw-r--r--libopie2/examples/opiecore/oprocessdemo/oprocessdemo.cpp11
-rw-r--r--libopie2/examples/opiecore/oprocessdemo/oprocessdemo.pro12
-rw-r--r--libopie2/opiecore/oprocess.cpp30
-rw-r--r--libopie2/opiecore/oprocess.h5
6 files changed, 65 insertions, 1 deletions
diff --git a/libopie2/examples/opiecore/opiecore.pro b/libopie2/examples/opiecore/opiecore.pro
index 8f3aedc..ec14be0 100644
--- a/libopie2/examples/opiecore/opiecore.pro
+++ b/libopie2/examples/opiecore/opiecore.pro
@@ -1,3 +1,3 @@
TEMPLATE = subdirs
-unix:SUBDIRS = odebugdemo oconfigdemo oglobalsettingsdemo
+unix:SUBDIRS = odebugdemo oconfigdemo oglobalsettingsdemo oprocessdemo
diff --git a/libopie2/examples/opiecore/oprocessdemo/.cvsignore b/libopie2/examples/opiecore/oprocessdemo/.cvsignore
new file mode 100644
index 0000000..8f7300c
--- a/dev/null
+++ b/libopie2/examples/opiecore/oprocessdemo/.cvsignore
@@ -0,0 +1,6 @@
+Makefile*
+moc*
+*moc
+*.o
+~*
+
diff --git a/libopie2/examples/opiecore/oprocessdemo/oprocessdemo.cpp b/libopie2/examples/opiecore/oprocessdemo/oprocessdemo.cpp
new file mode 100644
index 0000000..0abf53e
--- a/dev/null
+++ b/libopie2/examples/opiecore/oprocessdemo/oprocessdemo.cpp
@@ -0,0 +1,11 @@
+#include <opie2/oprocess.h>
+#include <iostream.h>
+
+int main( int argc, char** argv )
+{
+ printf( "my own PID seems to be '%d'\n", OProcess::processPID( "oprocessdemo" ) );
+ printf( "the PID of process 'Mickey' seems to be '%d'\n\n", OProcess::processPID( "Mickey" ) );
+
+ return 0;
+}
+
diff --git a/libopie2/examples/opiecore/oprocessdemo/oprocessdemo.pro b/libopie2/examples/opiecore/oprocessdemo/oprocessdemo.pro
new file mode 100644
index 0000000..72dac7f
--- a/dev/null
+++ b/libopie2/examples/opiecore/oprocessdemo/oprocessdemo.pro
@@ -0,0 +1,12 @@
+TEMPLATE = app
+CONFIG = qt warn_on debug
+HEADERS =
+SOURCES = oprocessdemo.cpp
+INCLUDEPATH += $(OPIEDIR)/include
+DEPENDPATH += $(OPIEDIR)/include
+LIBS += -lopiecore2
+TARGET = oprocessdemo
+
+include ( $(OPIEDIR)/include.pro )
+
+
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;
+ }
+}
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
@@ -463,2 +463,7 @@ public:
+ /**
+ * @return the PID of @a process, or -1 if the process is not running
+ */
+ static int processPID( const QString& process );
+
signals: