summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/sysinfo/processinfo.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/settings/sysinfo/processinfo.cpp b/noncore/settings/sysinfo/processinfo.cpp
index f9263ea..4ecb704 100644
--- a/noncore/settings/sysinfo/processinfo.cpp
+++ b/noncore/settings/sysinfo/processinfo.cpp
@@ -4,136 +4,136 @@
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> 26#include <qmessagebox.h>
27 27
28#include <sys/types.h> 28#include <sys/types.h>
29#include <signal.h> 29#include <signal.h>
30 30
31#include "processinfo.h" 31#include "processinfo.h"
32 32
33ProcessInfo::ProcessInfo( QWidget* parent, const char* name, WFlags fl ) 33ProcessInfo::ProcessInfo( QWidget* parent, const char* name, WFlags fl )
34 : QWidget( parent, name, fl ) 34 : QWidget( parent, name, fl )
35{ 35{
36 QVBoxLayout *vb = new QVBoxLayout( this, 5 ); 36 QVBoxLayout *vb = new QVBoxLayout( this, 5 );
37 37
38 ProcessView = new QListView( this, "ProcessView" ); 38 ProcessView = new QListView( this, "ProcessView" );
39 int colnum = ProcessView->addColumn( tr( "PID" ) ); 39 int colnum = ProcessView->addColumn( tr( "PID" ) );
40 ProcessView->setColumnAlignment( colnum, Qt::AlignRight ); 40 ProcessView->setColumnAlignment( colnum, Qt::AlignRight );
41 colnum = ProcessView->addColumn( tr( "Command" ),96 ); 41 colnum = ProcessView->addColumn( tr( "Command" ),96 );
42 ProcessView->setColumnAlignment( colnum, Qt::AlignRight ); 42 ProcessView->setColumnAlignment( colnum, Qt::AlignRight );
43 colnum = ProcessView->addColumn( tr( "Status" ) ); 43 colnum = ProcessView->addColumn( tr( "Status" ) );
44 ProcessView->setColumnAlignment( colnum, Qt::AlignRight ); 44 ProcessView->setColumnAlignment( colnum, Qt::AlignRight );
45 colnum = ProcessView->addColumn( tr( "Time" ) ); 45 colnum = ProcessView->addColumn( tr( "Time" ) );
46 ProcessView->setColumnAlignment( colnum, Qt::AlignRight ); 46 ProcessView->setColumnAlignment( colnum, Qt::AlignRight );
47 ProcessView->setAllColumnsShowFocus( TRUE ); 47 ProcessView->setAllColumnsShowFocus( TRUE );
48 connect( ProcessView, SIGNAL( doubleClicked(QListViewItem *) ), this, SLOT( viewProcess(QListViewItem *) ) ); 48 connect( ProcessView, SIGNAL( doubleClicked(QListViewItem *) ), this, SLOT( viewProcess(QListViewItem *) ) );
49 49
50 vb->addWidget( ProcessView ); 50 vb->addWidget( ProcessView );
51 51
52 QTimer *t = new QTimer( this ); 52 QTimer *t = new QTimer( this );
53 connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) ); 53 connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) );
54 t->start( 5000 ); 54 t->start( 5000 );
55 55
56 updateData(); 56 updateData();
57} 57}
58 58
59ProcessInfo::~ProcessInfo() 59ProcessInfo::~ProcessInfo()
60{ 60{
61} 61}
62 62
63void ProcessInfo::updateData() 63void ProcessInfo::updateData()
64{ 64{
65 QString processnum(""); 65 QString processnum("");
66 QString processcmd(""); 66 QString processcmd("");
67 QString processstatus(""); 67 QString processstatus("");
68 QString processtime(""); 68 QString processtime("");
69 int pid, ppid, pgrp, session, tty, tpgid, utime, stime, cutime, cstime, counter, priority, starttime, 69 int pid, ppid, pgrp, session, tty, tpgid, utime, stime, cutime, cstime, counter, priority, starttime,
70 signal, blocked, sigignore, sigcatch; 70 signal, blocked, sigignore, sigcatch;
71 uint flags, minflt, cminflt, majflt, cmajflt, timeout, itrealvalue, vsize, rss, rlim, startcode, 71 uint flags, minflt, cminflt, majflt, cmajflt, timeout, itrealvalue, vsize, rss, rlim, startcode,
72 endcode, startstack, kstkesp, kstkeip, wchan; 72 endcode, startstack, kstkesp, kstkeip, wchan;
73 char state; 73 char state;
74 char comm[255]; 74 char comm[255];
75 75
76 ProcessView->clear(); 76 ProcessView->clear();
77 77
78 QDir *procdir = new QDir("/proc"); 78 QDir *procdir = new QDir("/proc");
79 procdir->setFilter(QDir::Dirs); 79 procdir->setFilter(QDir::Dirs);
80 procdir->setSorting(QDir::Name); 80 procdir->setSorting(QDir::Name);
81 QFileInfoList *proclist = new QFileInfoList(*(procdir->entryInfoList())); 81 QFileInfoList *proclist = new QFileInfoList(*(procdir->entryInfoList()));
82 if ( proclist ) 82 if ( proclist )
83 { 83 {
84 QFileInfoListIterator it(*proclist); 84 QFileInfoListIterator it(*proclist);
85 QFileInfo *f; 85 QFileInfo *f;
86 while ( ( f = it.current() ) != 0 ) 86 while ( ( f = it.current() ) != 0 )
87 { 87 {
88 ++it; 88 ++it;
89 processnum = f->fileName(); 89 processnum = f->fileName();
90 if ( processnum >= "0" && processnum <= "99999" ) 90 if ( processnum >= "0" && processnum <= "99999" )
91 { 91 {
92 FILE *procfile = fopen( ( QString ) ( "/proc/" + processnum + "/stat"), "r"); 92 FILE *procfile = fopen( ( QString ) ( "/proc/" + processnum + "/stat"), "r");
93 93
94 if ( procfile ) 94 if ( procfile )
95 { 95 {
96 fscanf( procfile, 96 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", 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",
98 &pid, comm, &state, &ppid, &pgrp, &session,&tty, &tpgid, &flags, &minflt, &cminflt, 98 &pid, comm, &state, &ppid, &pgrp, &session,&tty, &tpgid, &flags, &minflt, &cminflt,
99 &majflt, &cmajflt, &utime, &stime, &cutime, &cstime, &counter, &priority, &timeout, 99 &majflt, &cmajflt, &utime, &stime, &cutime, &cstime, &counter, &priority, &timeout,
100 &itrealvalue, &starttime, &vsize, &rss, &rlim, &startcode, &endcode, &startstack, 100 &itrealvalue, &starttime, &vsize, &rss, &rlim, &startcode, &endcode, &startstack,
101 &kstkesp, &kstkeip, &signal, &blocked, &sigignore, &sigcatch, &wchan ); 101 &kstkesp, &kstkeip, &signal, &blocked, &sigignore, &sigcatch, &wchan );
102 processnum = processnum.rightJustify( 5, ' ' ); 102 processnum = processnum.rightJustify( 5, ' ' );
103 processcmd = QString( comm ).replace( QRegExp( "(" ), "" ); 103 processcmd = QString( comm ).replace( QRegExp( "(" ), "" );
104 processcmd = processcmd.replace( QRegExp( ")" ), "" ); 104 processcmd = processcmd.replace( QRegExp( ")" ), "" );
105 processstatus = state; 105 processstatus = state;
106 processtime.setNum( ( utime + stime ) / 100 ); 106 processtime.setNum( ( utime + stime ) / 100 );
107 processtime = processtime.rightJustify( 9, ' ' ); 107 processtime = processtime.rightJustify( 9, ' ' );
108 fclose( procfile ); 108 fclose( procfile );
109 109
110 ( void ) new QListViewItem( ProcessView, processnum, processcmd, processstatus, processtime ); 110 ( void ) new QListViewItem( ProcessView, processnum, processcmd, processstatus, processtime );
111 } 111 }
112 } 112 }
113 } 113 }
114 } 114 }
115 115
116 delete proclist; 116 delete proclist;
117 delete procdir; 117 delete procdir;
118} 118}
119 119
120void ProcessInfo::viewProcess(QListViewItem *process) 120void ProcessInfo::viewProcess(QListViewItem *process)
121{ 121{
122 QString pid= process->text(0); 122 QString pid= process->text(0);
123 QString command = process->text(1); 123 QString command = process->text(1);
124 switch( QMessageBox::information( this, (tr("Kill Process?")), 124 switch( QMessageBox::information( this, (tr("Kill Process?")),
125 (tr("You really want to kill\n"+command+" PID: "+pid+"?")), 125 (tr("You really want to kill\n"+command+" PID: "+pid+"?")),
126 (tr("Yes")), (tr("No")), 0 )){ 126 (tr("Yes")), (tr("No")), 0 )){
127 case 0: // Yes clicked, 127 case 0: // Yes clicked,
128 { 128 {
129 bool ok; 129 bool ok;
130 pid_t child=pid.toInt(&ok,10); 130 pid_t child=pid.toInt(&ok,10);
131 if((kill(child,SIGKILL)) < 0) 131 if((kill(child,SIGKILL)) < 0)
132 perror("kill:SIGTERM"); 132 perror("kill:SIGKILL");
133 } 133 }
134 break; 134 break;
135 case 1: // Cancel 135 case 1: // Cancel
136 break; 136 break;
137 }; 137 };
138//printf("Double click for PID: %s\n", process->text(0).stripWhiteSpace().latin1()); 138//printf("Double click for PID: %s\n", process->text(0).stripWhiteSpace().latin1());
139} 139}