Diffstat (limited to 'noncore/settings/sysinfo/processinfo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/sysinfo/processinfo.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/settings/sysinfo/processinfo.cpp b/noncore/settings/sysinfo/processinfo.cpp index 2a90b0f..69b4ab5 100644 --- a/noncore/settings/sysinfo/processinfo.cpp +++ b/noncore/settings/sysinfo/processinfo.cpp | |||
@@ -1,202 +1,202 @@ | |||
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 "processinfo.h" | 20 | #include "processinfo.h" |
21 | #include "detail.h" | 21 | #include "detail.h" |
22 | 22 | ||
23 | /* OPIE */ | 23 | /* OPIE */ |
24 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
25 | 25 | ||
26 | /* QT */ | 26 | /* QT */ |
27 | #include <qdir.h> | 27 | #include <qdir.h> |
28 | #include <qlayout.h> | 28 | #include <qlayout.h> |
29 | #include <qmessagebox.h> | 29 | #include <qmessagebox.h> |
30 | #include <qtimer.h> | 30 | #include <qtimer.h> |
31 | #include <qwhatsthis.h> | 31 | #include <qwhatsthis.h> |
32 | 32 | ||
33 | /* STD */ | 33 | /* STD */ |
34 | #include <sys/types.h> | 34 | #include <sys/types.h> |
35 | #include <signal.h> | 35 | #include <signal.h> |
36 | 36 | ||
37 | ProcessInfo::ProcessInfo( QWidget* parent, const char* name, WFlags fl ) | 37 | ProcessInfo::ProcessInfo( QWidget* parent, const char* name, WFlags fl ) |
38 | : QWidget( parent, name, fl ) | 38 | : QWidget( parent, name, fl ) |
39 | { | 39 | { |
40 | QGridLayout *layout = new QGridLayout( this ); | 40 | QGridLayout *layout = new QGridLayout( this ); |
41 | layout->setSpacing( 4 ); | 41 | layout->setSpacing( 4 ); |
42 | layout->setMargin( 4 ); | 42 | layout->setMargin( 4 ); |
43 | 43 | ||
44 | 44 | ||
45 | ProcessView = new QListView( this, "ProcessView" ); | 45 | ProcessView = new QListView( this, "ProcessView" ); |
46 | int colnum = ProcessView->addColumn( tr( "PID" ) ); | 46 | int colnum = ProcessView->addColumn( tr( "PID" ) ); |
47 | ProcessView->setColumnAlignment( colnum, Qt::AlignRight ); | 47 | ProcessView->setColumnAlignment( colnum, Qt::AlignRight ); |
48 | colnum = ProcessView->addColumn( tr( "Command" ),96 ); | 48 | colnum = ProcessView->addColumn( tr( "Command" ),96 ); |
49 | colnum = ProcessView->addColumn( tr( "Status" ) ); | 49 | colnum = ProcessView->addColumn( tr( "Status" ) ); |
50 | colnum = ProcessView->addColumn( tr( "Time" ) ); | 50 | colnum = ProcessView->addColumn( tr( "Time" ) ); |
51 | ProcessView->setColumnAlignment( colnum, Qt::AlignRight ); | 51 | ProcessView->setColumnAlignment( colnum, Qt::AlignRight ); |
52 | ProcessView->setAllColumnsShowFocus( TRUE ); | 52 | ProcessView->setAllColumnsShowFocus( TRUE ); |
53 | QPEApplication::setStylusOperation( ProcessView->viewport(), QPEApplication::RightOnHold ); | 53 | QPEApplication::setStylusOperation( ProcessView->viewport(), QPEApplication::RightOnHold ); |
54 | connect( ProcessView, SIGNAL( rightButtonPressed( QListViewItem *, const QPoint &, int ) ), | 54 | connect( ProcessView, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ), |
55 | this, SLOT( viewProcess( QListViewItem * ) ) ); | 55 | this, SLOT( viewProcess(QListViewItem*) ) ); |
56 | layout->addMultiCellWidget( ProcessView, 0, 0, 0, 1 ); | 56 | layout->addMultiCellWidget( ProcessView, 0, 0, 0, 1 ); |
57 | QWhatsThis::add( ProcessView, tr( "This is a list of all the processes on this handheld device.\n\nClick and hold on a process to see additional information about the process, or to send a signal to it." ) ); | 57 | QWhatsThis::add( ProcessView, tr( "This is a list of all the processes on this handheld device.\n\nClick and hold on a process to see additional information about the process, or to send a signal to it." ) ); |
58 | 58 | ||
59 | SignalCB = new QComboBox( FALSE, this, "SignalCB" ); | 59 | SignalCB = new QComboBox( FALSE, this, "SignalCB" ); |
60 | SignalCB->insertItem( " 1: SIGHUP" ); | 60 | SignalCB->insertItem( " 1: SIGHUP" ); |
61 | SignalCB->insertItem( " 2: SIGINT" ); | 61 | SignalCB->insertItem( " 2: SIGINT" ); |
62 | SignalCB->insertItem( " 3: SIGQUIT" ); | 62 | SignalCB->insertItem( " 3: SIGQUIT" ); |
63 | SignalCB->insertItem( " 5: SIGTRAP" ); | 63 | SignalCB->insertItem( " 5: SIGTRAP" ); |
64 | SignalCB->insertItem( " 6: SIGABRT" ); | 64 | SignalCB->insertItem( " 6: SIGABRT" ); |
65 | SignalCB->insertItem( " 9: SIGKILL" ); | 65 | SignalCB->insertItem( " 9: SIGKILL" ); |
66 | SignalCB->insertItem( "14: SIGALRM" ); | 66 | SignalCB->insertItem( "14: SIGALRM" ); |
67 | SignalCB->insertItem( "15: SIGTERM" ); | 67 | SignalCB->insertItem( "15: SIGTERM" ); |
68 | SignalCB->insertItem( "18: SIGCONT" ); | 68 | SignalCB->insertItem( "18: SIGCONT" ); |
69 | SignalCB->insertItem( "19: SIGSTOP" ); | 69 | SignalCB->insertItem( "19: SIGSTOP" ); |
70 | layout->addWidget( SignalCB, 1, 0 ); | 70 | layout->addWidget( SignalCB, 1, 0 ); |
71 | QWhatsThis::add( SignalCB, tr( "Select a signal here and then click the Send button to the right to send to this process." ) ); | 71 | QWhatsThis::add( SignalCB, tr( "Select a signal here and then click the Send button to the right to send to this process." ) ); |
72 | 72 | ||
73 | SendButton = new QPushButton( this, "SendButton" ); | 73 | SendButton = new QPushButton( this, "SendButton" ); |
74 | SendButton->setMinimumSize( QSize( 50, 24 ) ); | 74 | SendButton->setMinimumSize( QSize( 50, 24 ) ); |
75 | SendButton->setMaximumSize( QSize( 50, 24 ) ); | 75 | SendButton->setMaximumSize( QSize( 50, 24 ) ); |
76 | SendButton->setText( tr( "Send" ) ); | 76 | SendButton->setText( tr( "Send" ) ); |
77 | connect( SendButton, SIGNAL( clicked() ), this, SLOT( slotSendClicked() ) ); | 77 | connect( SendButton, SIGNAL( clicked() ), this, SLOT( slotSendClicked() ) ); |
78 | layout->addWidget( SendButton, 1, 1 ); | 78 | layout->addWidget( SendButton, 1, 1 ); |
79 | QWhatsThis::add( SendButton, tr( "Click here to send the selected signal to this process." ) ); | 79 | QWhatsThis::add( SendButton, tr( "Click here to send the selected signal to this process." ) ); |
80 | 80 | ||
81 | QTimer *t = new QTimer( this ); | 81 | QTimer *t = new QTimer( this ); |
82 | connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) ); | 82 | connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) ); |
83 | t->start( 5000 ); | 83 | t->start( 5000 ); |
84 | 84 | ||
85 | updateData(); | 85 | updateData(); |
86 | 86 | ||
87 | ProcessDtl = new Detail(); | 87 | ProcessDtl = new Detail(); |
88 | QWhatsThis::add( ProcessDtl->detailView, tr( "This area shows detailed information about this process." ) ); | 88 | QWhatsThis::add( ProcessDtl->detailView, tr( "This area shows detailed information about this process." ) ); |
89 | } | 89 | } |
90 | 90 | ||
91 | ProcessInfo::~ProcessInfo() | 91 | ProcessInfo::~ProcessInfo() |
92 | {} | 92 | {} |
93 | 93 | ||
94 | void ProcessInfo::updateData() | 94 | void ProcessInfo::updateData() |
95 | { | 95 | { |
96 | int pid, ppid, pgrp, session, tty, tpgid, utime, stime, cutime, cstime, counter, priority, starttime, | 96 | int pid, ppid, pgrp, session, tty, tpgid, utime, stime, cutime, cstime, counter, priority, starttime, |
97 | signal, blocked, sigignore, sigcatch; | 97 | signal, blocked, sigignore, sigcatch; |
98 | uint flags, minflt, cminflt, majflt, cmajflt, timeout, itrealvalue, vsize, rss, rlim, startcode, | 98 | uint flags, minflt, cminflt, majflt, cmajflt, timeout, itrealvalue, vsize, rss, rlim, startcode, |
99 | endcode, startstack, kstkesp, kstkeip, wchan; | 99 | endcode, startstack, kstkesp, kstkeip, wchan; |
100 | char state; | 100 | char state; |
101 | char comm[64]; | 101 | char comm[64]; |
102 | 102 | ||
103 | QString selectedpid; | 103 | QString selectedpid; |
104 | QListViewItem *curritem = ProcessView->currentItem(); | 104 | QListViewItem *curritem = ProcessView->currentItem(); |
105 | if ( curritem ) | 105 | if ( curritem ) |
106 | { | 106 | { |
107 | selectedpid = curritem->text( 0 ); | 107 | selectedpid = curritem->text( 0 ); |
108 | } | 108 | } |
109 | 109 | ||
110 | ProcessView->clear(); | 110 | ProcessView->clear(); |
111 | 111 | ||
112 | QListViewItem *newitem; | 112 | QListViewItem *newitem; |
113 | QListViewItem *selecteditem = 0x0; | 113 | QListViewItem *selecteditem = 0x0; |
114 | QDir *procdir = new QDir("/proc", 0, QDir::Name, QDir::Dirs); | 114 | QDir *procdir = new QDir("/proc", 0, QDir::Name, QDir::Dirs); |
115 | QFileInfoList *proclist = new QFileInfoList(*(procdir->entryInfoList())); | 115 | QFileInfoList *proclist = new QFileInfoList(*(procdir->entryInfoList())); |
116 | if ( proclist ) | 116 | if ( proclist ) |
117 | { | 117 | { |
118 | QFileInfoListIterator it(*proclist); | 118 | QFileInfoListIterator it(*proclist); |
119 | QFileInfo *f; | 119 | QFileInfo *f; |
120 | while ( ( f = it.current() ) != 0 ) | 120 | while ( ( f = it.current() ) != 0 ) |
121 | { | 121 | { |
122 | ++it; | 122 | ++it; |
123 | QString processnum = f->fileName(); | 123 | QString processnum = f->fileName(); |
124 | if ( processnum >= "1" && processnum <= "99999" ) | 124 | if ( processnum >= "1" && processnum <= "99999" ) |
125 | { | 125 | { |
126 | FILE *procfile = fopen( ( QString ) ( "/proc/" + processnum + "/stat"), "r"); | 126 | FILE *procfile = fopen( ( QString ) ( "/proc/" + processnum + "/stat"), "r"); |
127 | 127 | ||
128 | if ( procfile ) | 128 | if ( procfile ) |
129 | { | 129 | { |
130 | fscanf( procfile, | 130 | fscanf( procfile, |
131 | "%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", | 131 | "%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", |
132 | &pid, comm, &state, &ppid, &pgrp, &session,&tty, &tpgid, &flags, &minflt, &cminflt, | 132 | &pid, comm, &state, &ppid, &pgrp, &session,&tty, &tpgid, &flags, &minflt, &cminflt, |
133 | &majflt, &cmajflt, &utime, &stime, &cutime, &cstime, &counter, &priority, &timeout, | 133 | &majflt, &cmajflt, &utime, &stime, &cutime, &cstime, &counter, &priority, &timeout, |
134 | &itrealvalue, &starttime, &vsize, &rss, &rlim, &startcode, &endcode, &startstack, | 134 | &itrealvalue, &starttime, &vsize, &rss, &rlim, &startcode, &endcode, &startstack, |
135 | &kstkesp, &kstkeip, &signal, &blocked, &sigignore, &sigcatch, &wchan ); | 135 | &kstkesp, &kstkeip, &signal, &blocked, &sigignore, &sigcatch, &wchan ); |
136 | processnum = processnum.rightJustify( 5, ' ' ); | 136 | processnum = processnum.rightJustify( 5, ' ' ); |
137 | QString processcmd = QString( comm ).replace( QRegExp( "[()]" ), "" ); | 137 | QString processcmd = QString( comm ).replace( QRegExp( "[()]" ), "" ); |
138 | QString processstatus = QChar(state); | 138 | QString processstatus = QChar(state); |
139 | QString processtime = QString::number( ( utime + stime ) / 100 ); | 139 | QString processtime = QString::number( ( utime + stime ) / 100 ); |
140 | processtime = processtime.rightJustify( 9, ' ' ); | 140 | processtime = processtime.rightJustify( 9, ' ' ); |
141 | fclose( procfile ); | 141 | fclose( procfile ); |
142 | 142 | ||
143 | newitem = new QListViewItem( ProcessView, processnum, processcmd, processstatus, processtime ); | 143 | newitem = new QListViewItem( ProcessView, processnum, processcmd, processstatus, processtime ); |
144 | if ( processnum == selectedpid ) | 144 | if ( processnum == selectedpid ) |
145 | { | 145 | { |
146 | selecteditem = newitem; | 146 | selecteditem = newitem; |
147 | } | 147 | } |
148 | } | 148 | } |
149 | } | 149 | } |
150 | } | 150 | } |
151 | ProcessView->setCurrentItem( selecteditem ); | 151 | ProcessView->setCurrentItem( selecteditem ); |
152 | } | 152 | } |
153 | 153 | ||
154 | delete proclist; | 154 | delete proclist; |
155 | delete procdir; | 155 | delete procdir; |
156 | } | 156 | } |
157 | 157 | ||
158 | void ProcessInfo::slotSendClicked() | 158 | void ProcessInfo::slotSendClicked() |
159 | { | 159 | { |
160 | QListViewItem *currprocess = ProcessView->currentItem(); | 160 | QListViewItem *currprocess = ProcessView->currentItem(); |
161 | if ( !currprocess ) | 161 | if ( !currprocess ) |
162 | { | 162 | { |
163 | return; | 163 | return; |
164 | } | 164 | } |
165 | 165 | ||
166 | QString capstr = tr( "Really want to send %1\nto this process?" ).arg( SignalCB->currentText() ); | 166 | QString capstr = tr( "Really want to send %1\nto this process?" ).arg( SignalCB->currentText() ); |
167 | 167 | ||
168 | 168 | ||
169 | if ( QMessageBox::warning( this, currprocess->text( 1 ), capstr, | 169 | if ( QMessageBox::warning( this, currprocess->text( 1 ), capstr, |
170 | QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape ) == QMessageBox::Yes ) | 170 | QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape ) == QMessageBox::Yes ) |
171 | { | 171 | { |
172 | currprocess = ProcessView->currentItem(); | 172 | currprocess = ProcessView->currentItem(); |
173 | if ( currprocess ) | 173 | if ( currprocess ) |
174 | { | 174 | { |
175 | QString sigstr = SignalCB->currentText(); | 175 | QString sigstr = SignalCB->currentText(); |
176 | sigstr.truncate(2); | 176 | sigstr.truncate(2); |
177 | int sigid = sigstr.toUInt(); | 177 | int sigid = sigstr.toUInt(); |
178 | kill( currprocess->text( 0 ).stripWhiteSpace().toUInt(), sigid ); | 178 | kill( currprocess->text( 0 ).stripWhiteSpace().toUInt(), sigid ); |
179 | } | 179 | } |
180 | } | 180 | } |
181 | 181 | ||
182 | } | 182 | } |
183 | 183 | ||
184 | void ProcessInfo::viewProcess( QListViewItem *process ) | 184 | void ProcessInfo::viewProcess( QListViewItem *process ) |
185 | { | 185 | { |
186 | QString pid= process->text( 0 ).stripWhiteSpace(); | 186 | QString pid= process->text( 0 ).stripWhiteSpace(); |
187 | QString command = process->text( 1 ); | 187 | QString command = process->text( 1 ); |
188 | ProcessDtl->setCaption( pid + " - " + command ); | 188 | ProcessDtl->setCaption( pid + " - " + command ); |
189 | FILE *statfile = fopen( ( QString ) ( "/proc/" + pid + "/status"), "r"); | 189 | FILE *statfile = fopen( ( QString ) ( "/proc/" + pid + "/status"), "r"); |
190 | if ( statfile ) | 190 | if ( statfile ) |
191 | { | 191 | { |
192 | char line[81]; | 192 | char line[81]; |
193 | fgets( line, 81, statfile ); | 193 | fgets( line, 81, statfile ); |
194 | ProcessDtl->detailView->setText( line ); | 194 | ProcessDtl->detailView->setText( line ); |
195 | while ( fgets( line, 81, statfile ) ) | 195 | while ( fgets( line, 81, statfile ) ) |
196 | { | 196 | { |
197 | ProcessDtl->detailView->append( line ); | 197 | ProcessDtl->detailView->append( line ); |
198 | } | 198 | } |
199 | fclose( statfile ); | 199 | fclose( statfile ); |
200 | } | 200 | } |
201 | QPEApplication::showWidget( ProcessDtl ); | 201 | QPEApplication::showWidget( ProcessDtl ); |
202 | } | 202 | } |