Diffstat (limited to 'noncore/settings/sysinfo/processinfo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/sysinfo/processinfo.cpp | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/noncore/settings/sysinfo/processinfo.cpp b/noncore/settings/sysinfo/processinfo.cpp index 225da63..ad81d7b 100644 --- a/noncore/settings/sysinfo/processinfo.cpp +++ b/noncore/settings/sysinfo/processinfo.cpp | |||
@@ -22,13 +22,12 @@ | |||
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 | 26 | ||
27 | #include "processinfo.h" | 27 | #include "processinfo.h" |
28 | #include "processdetail.h" | ||
29 | 28 | ||
30 | ProcessInfo::ProcessInfo( QWidget* parent, const char* name, WFlags fl ) | 29 | ProcessInfo::ProcessInfo( QWidget* parent, const char* name, WFlags fl ) |
31 | : QWidget( parent, name, fl ) | 30 | : QWidget( parent, name, fl ) |
32 | { | 31 | { |
33 | QVBoxLayout *layout = new QVBoxLayout( this, 5 ); | 32 | QVBoxLayout *layout = new QVBoxLayout( this, 5 ); |
34 | 33 | ||
@@ -46,62 +45,58 @@ ProcessInfo::ProcessInfo( QWidget* parent, const char* name, WFlags fl ) | |||
46 | 45 | ||
47 | QTimer *t = new QTimer( this ); | 46 | QTimer *t = new QTimer( this ); |
48 | connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) ); | 47 | connect( t, SIGNAL( timeout() ), this, SLOT( updateData() ) ); |
49 | t->start( 5000 ); | 48 | t->start( 5000 ); |
50 | 49 | ||
51 | updateData(); | 50 | updateData(); |
51 | |||
52 | ProcessDtl = new ProcessDetail( 0, 0, 0 ); | ||
53 | ProcessDtl->ProcessView->setTextFormat( RichText ); | ||
52 | } | 54 | } |
53 | 55 | ||
54 | ProcessInfo::~ProcessInfo() | 56 | ProcessInfo::~ProcessInfo() |
55 | { | 57 | { |
56 | } | 58 | } |
57 | 59 | ||
58 | void ProcessInfo::updateData() | 60 | void ProcessInfo::updateData() |
59 | { | 61 | { |
60 | QString processnum(""); | ||
61 | QString processcmd(""); | ||
62 | QString processstatus(""); | ||
63 | QString processtime(""); | ||
64 | int pid, ppid, pgrp, session, tty, tpgid, utime, stime, cutime, cstime, counter, priority, starttime, | 62 | int pid, ppid, pgrp, session, tty, tpgid, utime, stime, cutime, cstime, counter, priority, starttime, |
65 | signal, blocked, sigignore, sigcatch; | 63 | signal, blocked, sigignore, sigcatch; |
66 | uint flags, minflt, cminflt, majflt, cmajflt, timeout, itrealvalue, vsize, rss, rlim, startcode, | 64 | uint flags, minflt, cminflt, majflt, cmajflt, timeout, itrealvalue, vsize, rss, rlim, startcode, |
67 | endcode, startstack, kstkesp, kstkeip, wchan; | 65 | endcode, startstack, kstkesp, kstkeip, wchan; |
68 | char state; | 66 | char state; |
69 | char comm[255]; | 67 | char comm[64]; |
70 | 68 | ||
71 | ProcessView->clear(); | 69 | ProcessView->clear(); |
72 | 70 | ||
73 | QDir *procdir = new QDir("/proc"); | 71 | QDir *procdir = new QDir("/proc", 0, QDir::Name, QDir::Dirs); |
74 | procdir->setFilter(QDir::Dirs); | ||
75 | procdir->setSorting(QDir::Name); | ||
76 | QFileInfoList *proclist = new QFileInfoList(*(procdir->entryInfoList())); | 72 | QFileInfoList *proclist = new QFileInfoList(*(procdir->entryInfoList())); |
77 | if ( proclist ) | 73 | if ( proclist ) |
78 | { | 74 | { |
79 | QFileInfoListIterator it(*proclist); | 75 | QFileInfoListIterator it(*proclist); |
80 | QFileInfo *f; | 76 | QFileInfo *f; |
81 | while ( ( f = it.current() ) != 0 ) | 77 | while ( ( f = it.current() ) != 0 ) |
82 | { | 78 | { |
83 | ++it; | 79 | ++it; |
84 | processnum = f->fileName(); | 80 | QString processnum = f->fileName(); |
85 | if ( processnum >= "0" && processnum <= "99999" ) | 81 | if ( processnum >= "1" && processnum <= "99999" ) |
86 | { | 82 | { |
87 | FILE *procfile = fopen( ( QString ) ( "/proc/" + processnum + "/stat"), "r"); | 83 | FILE *procfile = fopen( ( QString ) ( "/proc/" + processnum + "/stat"), "r"); |
88 | 84 | ||
89 | if ( procfile ) | 85 | if ( procfile ) |
90 | { | 86 | { |
91 | fscanf( procfile, | 87 | fscanf( procfile, |
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", | 88 | "%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", |
93 | &pid, comm, &state, &ppid, &pgrp, &session,&tty, &tpgid, &flags, &minflt, &cminflt, | 89 | &pid, comm, &state, &ppid, &pgrp, &session,&tty, &tpgid, &flags, &minflt, &cminflt, |
94 | &majflt, &cmajflt, &utime, &stime, &cutime, &cstime, &counter, &priority, &timeout, | 90 | &majflt, &cmajflt, &utime, &stime, &cutime, &cstime, &counter, &priority, &timeout, |
95 | &itrealvalue, &starttime, &vsize, &rss, &rlim, &startcode, &endcode, &startstack, | 91 | &itrealvalue, &starttime, &vsize, &rss, &rlim, &startcode, &endcode, &startstack, |
96 | &kstkesp, &kstkeip, &signal, &blocked, &sigignore, &sigcatch, &wchan ); | 92 | &kstkesp, &kstkeip, &signal, &blocked, &sigignore, &sigcatch, &wchan ); |
97 | processnum = processnum.rightJustify( 5, ' ' ); | 93 | processnum = processnum.rightJustify( 5, ' ' ); |
98 | processcmd = QString( comm ).replace( QRegExp( "(" ), "" ); | 94 | QString processcmd = QString( comm ).replace( QRegExp( "[()]" ), "" ); |
99 | processcmd = processcmd.replace( QRegExp( ")" ), "" ); | 95 | QString processstatus = QChar(state); |
100 | processstatus = state; | 96 | QString processtime = QString::number( ( utime + stime ) / 100 ); |
101 | processtime.setNum( ( utime + stime ) / 100 ); | ||
102 | processtime = processtime.rightJustify( 9, ' ' ); | 97 | processtime = processtime.rightJustify( 9, ' ' ); |
103 | fclose( procfile ); | 98 | fclose( procfile ); |
104 | 99 | ||
105 | ( void ) new QListViewItem( ProcessView, processnum, processcmd, processstatus, processtime ); | 100 | ( void ) new QListViewItem( ProcessView, processnum, processcmd, processstatus, processtime ); |
106 | } | 101 | } |
107 | } | 102 | } |
@@ -111,27 +106,25 @@ void ProcessInfo::updateData() | |||
111 | delete proclist; | 106 | delete proclist; |
112 | delete procdir; | 107 | delete procdir; |
113 | } | 108 | } |
114 | 109 | ||
115 | void ProcessInfo::viewProcess(QListViewItem *process) | 110 | void ProcessInfo::viewProcess(QListViewItem *process) |
116 | { | 111 | { |
117 | QString pid= process->text(0).stripWhiteSpace(); | 112 | QString pid= process->text( 0 ).stripWhiteSpace(); |
118 | QString command = process->text(1); | 113 | QString command = process->text( 1 ); |
119 | ProcessDetail *processdtl = new ProcessDetail( this, 0, TRUE, 0); | 114 | ProcessDtl->setCaption( pid + " - " + command ); |
120 | processdtl->setCaption( pid + " - " + command ); | 115 | ProcessDtl->pid = pid.toUInt(); |
121 | processdtl->pid = pid.toUInt(); | ||
122 | processdtl->ProcessView->setTextFormat( RichText ); | ||
123 | FILE *statfile = fopen( ( QString ) ( "/proc/" + pid + "/status"), "r"); | 116 | FILE *statfile = fopen( ( QString ) ( "/proc/" + pid + "/status"), "r"); |
124 | if ( statfile ) | 117 | if ( statfile ) |
125 | { | 118 | { |
126 | char line[81]; | 119 | char line[81]; |
127 | fgets( line, 81, statfile ); | 120 | fgets( line, 81, statfile ); |
128 | processdtl->ProcessView->setText( line ); | 121 | ProcessDtl->ProcessView->setText( line ); |
129 | while ( fgets( line, 81, statfile ) ) | 122 | while ( fgets( line, 81, statfile ) ) |
130 | { | 123 | { |
131 | processdtl->ProcessView->append( line ); | 124 | ProcessDtl->ProcessView->append( line ); |
132 | } | 125 | } |
133 | fclose( statfile ); | 126 | fclose( statfile ); |
134 | } | 127 | } |
135 | 128 | ||
136 | processdtl->showMaximized(); | 129 | ProcessDtl->showMaximized(); |
137 | } | 130 | } |