summaryrefslogtreecommitdiff
authorbipolar <bipolar>2002-03-07 02:27:02 (UTC)
committer bipolar <bipolar>2002-03-07 02:27:02 (UTC)
commit09444065297662fca1396abf8c0c9dd00380699f (patch) (unidiff)
tree1e7fbec969b991e5f75406674679d450daa94889
parentfc2c85782429209229228602b6149248635597a5 (diff)
downloadopie-09444065297662fca1396abf8c0c9dd00380699f.zip
opie-09444065297662fca1396abf8c0c9dd00380699f.tar.gz
opie-09444065297662fca1396abf8c0c9dd00380699f.tar.bz2
ljp: added processinfo for drw
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/sysinfo/processdetail.cpp85
-rw-r--r--noncore/settings/sysinfo/processdetail.h47
-rw-r--r--noncore/settings/sysinfo/processinfo.cpp44
-rw-r--r--noncore/settings/sysinfo/sysinfo.pro4
4 files changed, 156 insertions, 24 deletions
diff --git a/noncore/settings/sysinfo/processdetail.cpp b/noncore/settings/sysinfo/processdetail.cpp
new file mode 100644
index 0000000..1ca1e72
--- a/dev/null
+++ b/noncore/settings/sysinfo/processdetail.cpp
@@ -0,0 +1,85 @@
1/**********************************************************************
2** ProcessDetail
3**
4** Display process information
5**
6** Copyright (C) 2002, Dan Williams
7** williamsdr@acm.org
8** http://draknor.net
9**
10** This file may be distributed and/or modified under the terms of the
11** GNU General Public License version 2 as published by the Free Software
12** Foundation and appearing in the file LICENSE.GPL included in the
13** packaging of this file.
14**
15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17**
18**********************************************************************/
19
20#include "processdetail.h"
21
22#include <sys/types.h>
23#include <signal.h>
24
25#include <qcombobox.h>
26#include <qpushbutton.h>
27#include <qtextview.h>
28#include <qlayout.h>
29#include <qlistview.h>
30#include <qmessagebox.h>
31
32ProcessDetail::ProcessDetail( QWidget* parent, const char* name, bool modal, WFlags fl )
33 : QDialog( parent, name, modal, fl )
34{
35 pid = 0;
36
37 QGridLayout *layout = new QGridLayout( this );
38 layout->setSpacing( 6 );
39 layout->setMargin( 11 );
40
41 SignalCB = new QComboBox( FALSE, this, "SignalCB" );
42 SignalCB->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)7, SignalCB->sizePolicy().hasHeightForWidth() ) );
43 SignalCB->setMinimumSize( QSize( 50, 24 ) );
44 SignalCB->setMaximumSize( QSize( 600, 24 ) );
45 SignalCB->insertItem( " 1: SIGHUP" );
46 SignalCB->insertItem( " 9: SIGKILL" );
47 SignalCB->insertItem( "15: SIGTERM" );
48 layout->addWidget( SignalCB, 1, 0 );
49
50 ProcessView = new QTextView( this, "ProcessView" );
51 ProcessView->setFrameShadow( QTextView::Plain );
52 layout->addMultiCellWidget( ProcessView, 0, 0, 0, 1 );
53
54 SendButton = new QPushButton( this, "SendButton" );
55 SendButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, SendButton->sizePolicy().hasHeightForWidth() ) );
56 SendButton->setMinimumSize( QSize( 50, 24 ) );
57 SendButton->setMaximumSize( QSize( 50, 24 ) );
58 SendButton->setText( tr( "Send" ) );
59 connect( SendButton, SIGNAL( clicked() ), this, SLOT( slotSendClicked() ) );
60 layout->addWidget( SendButton, 1, 1 );
61}
62
63ProcessDetail::~ProcessDetail()
64{
65}
66
67void ProcessDetail::slotSendClicked()
68{
69 QString sigstr = SignalCB->currentText();
70 sigstr.truncate(2);
71 int sigid = sigstr.toUInt();
72
73 if ( !QMessageBox::information( this, caption(),
74 ( tr( "You really want to send\n" + SignalCB->currentText() + "\nto this process?") ),
75 ( tr( "Yes" ) ), ( tr( "No" ) ), 0 ) )
76 {
77 if ( kill( pid, sigid ) == 0 )
78 {
79 accept();
80 }
81 }
82
83}
84
85
diff --git a/noncore/settings/sysinfo/processdetail.h b/noncore/settings/sysinfo/processdetail.h
new file mode 100644
index 0000000..5d418ac
--- a/dev/null
+++ b/noncore/settings/sysinfo/processdetail.h
@@ -0,0 +1,47 @@
1/**********************************************************************
2** ProcessDetail
3**
4** Display process information
5**
6** Copyright (C) 2002, Dan Williams
7** williamsdr@acm.org
8** http://draknor.net
9**
10** This file may be distributed and/or modified under the terms of the
11** GNU General Public License version 2 as published by the Free Software
12** Foundation and appearing in the file LICENSE.GPL included in the
13** packaging of this file.
14**
15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17**
18**********************************************************************/
19
20#ifndef PROCESSDETAIL_H
21#define PROCESSDETAIL_H
22
23#include <qdialog.h>
24#include <qcombo.h>
25#include <qtextview.h>
26#include <qpushbutton.h>
27#include <qlistview.h>
28
29class ProcessDetail : public QDialog
30{
31 Q_OBJECT
32
33public:
34 ProcessDetail( QWidget* parent, const char* name, bool modal, WFlags fl );
35 ~ProcessDetail();
36
37 QComboBox* SignalCB;
38 QTextView* ProcessView;
39 QPushButton* SendButton;
40
41 int pid;
42
43private slots:
44 void slotSendClicked();
45};
46
47#endif // PROCESSDETAIL_H
diff --git a/noncore/settings/sysinfo/processinfo.cpp b/noncore/settings/sysinfo/processinfo.cpp
index 4ecb704..225da63 100644
--- a/noncore/settings/sysinfo/processinfo.cpp
+++ b/noncore/settings/sysinfo/processinfo.cpp
@@ -1,139 +1,137 @@
1/********************************************************************** 1/**********************************************************************
2** ProcessInfo 2** ProcessInfo
3** 3**
4** Display process information 4** Display process information
5** 5**
6** Copyright (C) 2002, Dan Williams 6** Copyright (C) 2002, Dan Williams
7** williamsdr@acm.org 7** williamsdr@acm.org
8** http://draknor.net 8** http://draknor.net
9** 9**
10** This file may be distributed and/or modified under the terms of the 10** This file may be distributed and/or modified under the terms of the
11** GNU General Public License version 2 as published by the Free Software 11** GNU General Public License version 2 as published by the Free Software
12** Foundation and appearing in the file LICENSE.GPL included in the 12** Foundation and appearing in the file LICENSE.GPL included in the
13** packaging of this file. 13** packaging of this file.
14** 14**
15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17** 17**
18**********************************************************************/ 18**********************************************************************/
19 19
20#include <qheader.h> 20#include <qheader.h>
21#include <qlistview.h> 21#include <qlistview.h>
22#include <qlayout.h> 22#include <qlayout.h>
23#include <qtimer.h> 23#include <qtimer.h>
24#include <qfile.h> 24#include <qfile.h>
25#include <qdir.h> 25#include <qdir.h>
26#include <qmessagebox.h>
27
28#include <sys/types.h>
29#include <signal.h>
30 26
31#include "processinfo.h" 27#include "processinfo.h"
28#include "processdetail.h"
32 29
33ProcessInfo::ProcessInfo( QWidget* parent, const char* name, WFlags fl ) 30ProcessInfo::ProcessInfo( QWidget* parent, const char* name, WFlags fl )
34 : QWidget( parent, name, fl ) 31 : QWidget( parent, name, fl )
35{ 32{
36 QVBoxLayout *vb = new QVBoxLayout( this, 5 ); 33 QVBoxLayout *layout = new QVBoxLayout( this, 5 );
37 34
38 ProcessView = new QListView( this, "ProcessView" ); 35 ProcessView = new QListView( this, "ProcessView" );
39 int colnum = ProcessView->addColumn( tr( "PID" ) ); 36 int colnum = ProcessView->addColumn( tr( "PID" ) );
40 ProcessView->setColumnAlignment( colnum, Qt::AlignRight ); 37 ProcessView->setColumnAlignment( colnum, Qt::AlignRight );
41 colnum = ProcessView->addColumn( tr( "Command" ),96 ); 38 colnum = ProcessView->addColumn( tr( "Command" ),96 );
42 ProcessView->setColumnAlignment( colnum, Qt::AlignRight );
43 colnum = ProcessView->addColumn( tr( "Status" ) ); 39 colnum = ProcessView->addColumn( tr( "Status" ) );
44 ProcessView->setColumnAlignment( colnum, Qt::AlignRight );
45 colnum = ProcessView->addColumn( tr( "Time" ) ); 40 colnum = ProcessView->addColumn( tr( "Time" ) );
46 ProcessView->setColumnAlignment( colnum, Qt::AlignRight ); 41 ProcessView->setColumnAlignment( colnum, Qt::AlignRight );
47 ProcessView->setAllColumnsShowFocus( TRUE ); 42 ProcessView->setAllColumnsShowFocus( TRUE );
48 connect( ProcessView, SIGNAL( doubleClicked(QListViewItem *) ), this, SLOT( viewProcess(QListViewItem *) ) ); 43 connect( ProcessView, SIGNAL( doubleClicked(QListViewItem *) ), this, SLOT( viewProcess(QListViewItem *) ) );
49 44
50 vb->addWidget( ProcessView ); 45 layout->addWidget( ProcessView );
51 46
52 QTimer *t = new QTimer( this ); 47 QTimer *t = new QTimer( this );
53 connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) ); 48 connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) );
54 t->start( 5000 ); 49 t->start( 5000 );
55 50
56 updateData(); 51 updateData();
57} 52}
58 53
59ProcessInfo::~ProcessInfo() 54ProcessInfo::~ProcessInfo()
60{ 55{
61} 56}
62 57
63void ProcessInfo::updateData() 58void ProcessInfo::updateData()
64{ 59{
65 QString processnum(""); 60 QString processnum("");
66 QString processcmd(""); 61 QString processcmd("");
67 QString processstatus(""); 62 QString processstatus("");
68 QString processtime(""); 63 QString processtime("");
69 int pid, ppid, pgrp, session, tty, tpgid, utime, stime, cutime, cstime, counter, priority, starttime, 64 int pid, ppid, pgrp, session, tty, tpgid, utime, stime, cutime, cstime, counter, priority, starttime,
70 signal, blocked, sigignore, sigcatch; 65 signal, blocked, sigignore, sigcatch;
71 uint flags, minflt, cminflt, majflt, cmajflt, timeout, itrealvalue, vsize, rss, rlim, startcode, 66 uint flags, minflt, cminflt, majflt, cmajflt, timeout, itrealvalue, vsize, rss, rlim, startcode,
72 endcode, startstack, kstkesp, kstkeip, wchan; 67 endcode, startstack, kstkesp, kstkeip, wchan;
73 char state; 68 char state;
74 char comm[255]; 69 char comm[255];
75 70
76 ProcessView->clear(); 71 ProcessView->clear();
77 72
78 QDir *procdir = new QDir("/proc"); 73 QDir *procdir = new QDir("/proc");
79 procdir->setFilter(QDir::Dirs); 74 procdir->setFilter(QDir::Dirs);
80 procdir->setSorting(QDir::Name); 75 procdir->setSorting(QDir::Name);
81 QFileInfoList *proclist = new QFileInfoList(*(procdir->entryInfoList())); 76 QFileInfoList *proclist = new QFileInfoList(*(procdir->entryInfoList()));
82 if ( proclist ) 77 if ( proclist )
83 { 78 {
84 QFileInfoListIterator it(*proclist); 79 QFileInfoListIterator it(*proclist);
85 QFileInfo *f; 80 QFileInfo *f;
86 while ( ( f = it.current() ) != 0 ) 81 while ( ( f = it.current() ) != 0 )
87 { 82 {
88 ++it; 83 ++it;
89 processnum = f->fileName(); 84 processnum = f->fileName();
90 if ( processnum >= "0" && processnum <= "99999" ) 85 if ( processnum >= "0" && processnum <= "99999" )
91 { 86 {
92 FILE *procfile = fopen( ( QString ) ( "/proc/" + processnum + "/stat"), "r"); 87 FILE *procfile = fopen( ( QString ) ( "/proc/" + processnum + "/stat"), "r");
93 88
94 if ( procfile ) 89 if ( procfile )
95 { 90 {
96 fscanf( procfile, 91 fscanf( procfile,
97 "%d %s %c %d %d %d %d %d %u %u %u %u %u %d %d %d %d %d %d %u %u %d %u %u %u %u %u %u %u %u %d %d %d %d %u", 92 "%d %s %c %d %d %d %d %d %u %u %u %u %u %d %d %d %d %d %d %u %u %d %u %u %u %u %u %u %u %u %d %d %d %d %u",
98 &pid, comm, &state, &ppid, &pgrp, &session,&tty, &tpgid, &flags, &minflt, &cminflt, 93 &pid, comm, &state, &ppid, &pgrp, &session,&tty, &tpgid, &flags, &minflt, &cminflt,
99 &majflt, &cmajflt, &utime, &stime, &cutime, &cstime, &counter, &priority, &timeout, 94 &majflt, &cmajflt, &utime, &stime, &cutime, &cstime, &counter, &priority, &timeout,
100 &itrealvalue, &starttime, &vsize, &rss, &rlim, &startcode, &endcode, &startstack, 95 &itrealvalue, &starttime, &vsize, &rss, &rlim, &startcode, &endcode, &startstack,
101 &kstkesp, &kstkeip, &signal, &blocked, &sigignore, &sigcatch, &wchan ); 96 &kstkesp, &kstkeip, &signal, &blocked, &sigignore, &sigcatch, &wchan );
102 processnum = processnum.rightJustify( 5, ' ' ); 97 processnum = processnum.rightJustify( 5, ' ' );
103 processcmd = QString( comm ).replace( QRegExp( "(" ), "" ); 98 processcmd = QString( comm ).replace( QRegExp( "(" ), "" );
104 processcmd = processcmd.replace( QRegExp( ")" ), "" ); 99 processcmd = processcmd.replace( QRegExp( ")" ), "" );
105 processstatus = state; 100 processstatus = state;
106 processtime.setNum( ( utime + stime ) / 100 ); 101 processtime.setNum( ( utime + stime ) / 100 );
107 processtime = processtime.rightJustify( 9, ' ' ); 102 processtime = processtime.rightJustify( 9, ' ' );
108 fclose( procfile ); 103 fclose( procfile );
109 104
110 ( void ) new QListViewItem( ProcessView, processnum, processcmd, processstatus, processtime ); 105 ( void ) new QListViewItem( ProcessView, processnum, processcmd, processstatus, processtime );
111 } 106 }
112 } 107 }
113 } 108 }
114 } 109 }
115 110
116 delete proclist; 111 delete proclist;
117 delete procdir; 112 delete procdir;
118} 113}
119 114
120void ProcessInfo::viewProcess(QListViewItem *process) 115void ProcessInfo::viewProcess(QListViewItem *process)
121{ 116{
122 QString pid= process->text(0); 117 QString pid= process->text(0).stripWhiteSpace();
123 QString command = process->text(1); 118 QString command = process->text(1);
124 switch( QMessageBox::information( this, (tr("Kill Process?")), 119 ProcessDetail *processdtl = new ProcessDetail( this, 0, TRUE, 0);
125 (tr("You really want to kill\n"+command+" PID: "+pid+"?")), 120 processdtl->setCaption( pid + " - " + command );
126 (tr("Yes")), (tr("No")), 0 )){ 121 processdtl->pid = pid.toUInt();
127 case 0: // Yes clicked, 122 processdtl->ProcessView->setTextFormat( RichText );
123 FILE *statfile = fopen( ( QString ) ( "/proc/" + pid + "/status"), "r");
124 if ( statfile )
125 {
126 char line[81];
127 fgets( line, 81, statfile );
128 processdtl->ProcessView->setText( line );
129 while ( fgets( line, 81, statfile ) )
128 { 130 {
129 bool ok; 131 processdtl->ProcessView->append( line );
130 pid_t child=pid.toInt(&ok,10); 132 }
131 if((kill(child,SIGKILL)) < 0) 133 fclose( statfile );
132 perror("kill:SIGKILL"); 134 }
133 } 135
134 break; 136 processdtl->showMaximized();
135 case 1: // Cancel
136 break;
137 };
138//printf("Double click for PID: %s\n", process->text(0).stripWhiteSpace().latin1());
139} 137}
diff --git a/noncore/settings/sysinfo/sysinfo.pro b/noncore/settings/sysinfo/sysinfo.pro
index 7f84dec..f14716e 100644
--- a/noncore/settings/sysinfo/sysinfo.pro
+++ b/noncore/settings/sysinfo/sysinfo.pro
@@ -1,27 +1,29 @@
1TEMPLATE = app 1TEMPLATE = app
2CONFIG = qt warn_on release 2CONFIG = qt warn_on release
3DESTDIR = $(OPIEDIR)/bin 3DESTDIR = $(OPIEDIR)/bin
4HEADERS = memory.h \ 4HEADERS = memory.h \
5 graph.h \ 5 graph.h \
6 load.h \ 6 load.h \
7 storage.h \ 7 storage.h \
8 processinfo.h \ 8 processinfo.h \
9 processdetail.h \
9 versioninfo.h \ 10 versioninfo.h \
10 sysinfo.h 11 sysinfo.h
11SOURCES = main.cpp \ 12SOURCES = main.cpp \
12 memory.cpp \ 13 memory.cpp \
13 graph.cpp \ 14 graph.cpp \
14 load.cpp \ 15 load.cpp \
15 storage.cpp \ 16 storage.cpp \
16 processinfo.cpp \ 17 processinfo.cpp \
18 processdetail.cpp \
17 versioninfo.cpp \ 19 versioninfo.cpp \
18 sysinfo.cpp 20 sysinfo.cpp
19INTERFACES = 21INTERFACES =
20 22
21INCLUDEPATH += $(OPIEDIR)/include 23INCLUDEPATH += $(OPIEDIR)/include
22DEPENDPATH += $(OPIEDIR)/include 24DEPENDPATH += $(OPIEDIR)/include
23LIBS += -lqpe 25LIBS += -lqpe
24 26
25TARGET = sysinfo 27TARGET = sysinfo
26 28
27TRANSLATIONS = ../i18n/de/sysinfo.ts 29TRANSLATIONS = ../i18n/de/sysinfo.ts