Changeset View
Changeset View
Standalone View
Standalone View
ksysguardd/Linux/ProcessList.c
Show First 20 Lines • Show All 184 Lines • ▼ Show 20 Line(s) | 111 | typedef struct { | |||
---|---|---|---|---|---|
185 | char name[ 64 ]; | 185 | char name[ 64 ]; | ||
186 | 186 | | |||
187 | /** The command used to start the process */ | 187 | /** The command used to start the process */ | ||
188 | char cmdline[ 256 ]; | 188 | char cmdline[ 256 ]; | ||
189 | 189 | | |||
190 | /** The login name of the user that owns this process */ | 190 | /** The login name of the user that owns this process */ | ||
191 | char userName[ 32 ]; | 191 | char userName[ 32 ]; | ||
192 | 192 | | |||
193 | /** NoNewPrivileges: task can't gain higher privileges via setuid etc. */ | ||||
194 | int noNewPrivileges; | ||||
195 | | ||||
193 | } ProcessInfo; | 196 | } ProcessInfo; | ||
194 | 197 | | |||
195 | void getIOnice( int pid, ProcessInfo *ps ); | 198 | void getIOnice( int pid, ProcessInfo *ps ); | ||
196 | void ioniceProcess( const char* cmd ); | 199 | void ioniceProcess( const char* cmd ); | ||
197 | 200 | | |||
198 | static unsigned ProcessCount; | 201 | static unsigned ProcessCount; | ||
199 | static DIR* procDir; | 202 | static DIR* procDir; | ||
200 | static void validateStr( char* str ) | 203 | static void validateStr( char* str ) | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 240 | for ( ;; ) { | |||
246 | } else if ( strcmp( tag, "Uid:" ) == 0 ) { | 249 | } else if ( strcmp( tag, "Uid:" ) == 0 ) { | ||
247 | sscanf( buf, "%*s %d %*d %*d %*d", (int*)&ps->uid ); | 250 | sscanf( buf, "%*s %d %*d %*d %*d", (int*)&ps->uid ); | ||
248 | } else if ( strcmp( tag, "Gid:" ) == 0 ) { | 251 | } else if ( strcmp( tag, "Gid:" ) == 0 ) { | ||
249 | sscanf( buf, "%*s %d %*d %*d %*d", (int*)&ps->gid ); | 252 | sscanf( buf, "%*s %d %*d %*d %*d", (int*)&ps->gid ); | ||
250 | } else if ( strcmp( tag, "TracerPid:" ) == 0 ) { | 253 | } else if ( strcmp( tag, "TracerPid:" ) == 0 ) { | ||
251 | sscanf( buf, "%*s %d", (int*)&ps->tracerpid ); | 254 | sscanf( buf, "%*s %d", (int*)&ps->tracerpid ); | ||
252 | if (ps->tracerpid == 0) | 255 | if (ps->tracerpid == 0) | ||
253 | ps->tracerpid = -1; /* ksysguard uses -1 to indicate no tracerpid, but linux uses 0 */ | 256 | ps->tracerpid = -1; /* ksysguard uses -1 to indicate no tracerpid, but linux uses 0 */ | ||
257 | } else if ( strcmp( tag, "NoNewPrivs:" ) == 0 ) { | ||||
258 | sscanf( buf, "%*s %d", &ps->noNewPrivileges ); | ||||
254 | } | 259 | } | ||
255 | } | 260 | } | ||
256 | 261 | | |||
257 | if ( fclose( fd ) ) | 262 | if ( fclose( fd ) ) | ||
258 | return false; | 263 | return false; | ||
259 | 264 | | |||
260 | snprintf( buf, BUFSIZE - 1, "/proc/%d/stat", pid ); | 265 | snprintf( buf, BUFSIZE - 1, "/proc/%d/stat", pid ); | ||
261 | buf[ BUFSIZE - 1 ] = '\0'; | 266 | buf[ BUFSIZE - 1 ] = '\0'; | ||
▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Line(s) | 410 | { | |||
409 | ProcessInfo ps; | 414 | ProcessInfo ps; | ||
410 | ProcessCount = 0; | 415 | ProcessCount = 0; | ||
411 | rewinddir(procDir); | 416 | rewinddir(procDir); | ||
412 | while ( ( entry = readdir( procDir ) ) ) { | 417 | while ( ( entry = readdir( procDir ) ) ) { | ||
413 | if ( isdigit( entry->d_name[ 0 ] ) ) { | 418 | if ( isdigit( entry->d_name[ 0 ] ) ) { | ||
414 | long pid; | 419 | long pid; | ||
415 | pid = atol( entry->d_name ); | 420 | pid = atol( entry->d_name ); | ||
416 | if(getProcess( pid, &ps )) /* Print out the details of the process. Because of a stupid bug in kde3 ksysguard, make sure cmdline and tty are not empty */ | 421 | if(getProcess( pid, &ps )) /* Print out the details of the process. Because of a stupid bug in kde3 ksysguard, make sure cmdline and tty are not empty */ | ||
417 | output( "%s\t%ld\t%ld\t%lu\t%lu\t%s\t%lu\t%lu\t%d\t%lu\t%lu\t%lu\t%s\t%ld\t%s\t%s\t%d\t%d\n", | 422 | output( "%s\t%ld\t%ld\t%lu\t%lu\t%s\t%lu\t%lu\t%d\t%lu\t%lu\t%lu\t%s\t%ld\t%s\t%s\t%d\t%d\t%d\n", | ||
418 | ps.name, pid, (long)ps.ppid, | 423 | ps.name, pid, (long)ps.ppid, | ||
419 | (long)ps.uid, (long)ps.gid, ps.status, ps.userTime, | 424 | (long)ps.uid, (long)ps.gid, ps.status, ps.userTime, | ||
420 | ps.sysTime, ps.niceLevel, ps.vmSize, ps.vmRss, ps.vmURss, | 425 | ps.sysTime, ps.niceLevel, ps.vmSize, ps.vmRss, ps.vmURss, | ||
421 | (ps.userName[0]==0)?" ":ps.userName, (long)ps.tracerpid, | 426 | (ps.userName[0]==0)?" ":ps.userName, (long)ps.tracerpid, | ||
422 | (ps.tty[0]==0)?" ":ps.tty, (ps.cmdline[0]==0)?" ":ps.cmdline, | 427 | (ps.tty[0]==0)?" ":ps.tty, (ps.cmdline[0]==0)?" ":ps.cmdline, | ||
423 | ps.ioPriorityClass, ps.ioPriority | 428 | ps.ioPriorityClass, ps.ioPriority, ps.noNewPrivileges | ||
424 | ); | 429 | ); | ||
425 | } | 430 | } | ||
426 | } | 431 | } | ||
427 | output( "\n" ); | 432 | output( "\n" ); | ||
428 | return; | 433 | return; | ||
429 | } | 434 | } | ||
430 | 435 | | |||
431 | void getIOnice( int pid, ProcessInfo *ps ) { | 436 | void getIOnice( int pid, ProcessInfo *ps ) { | ||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Line(s) | 482 | { | |||
486 | 491 | | |||
487 | exitPWUIDCache(); | 492 | exitPWUIDCache(); | ||
488 | } | 493 | } | ||
489 | 494 | | |||
490 | void printProcessListInfo( const char* cmd ) | 495 | void printProcessListInfo( const char* cmd ) | ||
491 | { | 496 | { | ||
492 | (void)cmd; | 497 | (void)cmd; | ||
493 | output( "Name\tPID\tPPID\tUID\tGID\tStatus\tUser Time\tSystem Time\tNice\tVmSize" | 498 | output( "Name\tPID\tPPID\tUID\tGID\tStatus\tUser Time\tSystem Time\tNice\tVmSize" | ||
494 | "\tVmRss\tVmURss\tLogin\tTracerPID\tTTY\tCommand\tIO Priority Class\tIO Priority\n" ); | 499 | "\tVmRss\tVmURss\tLogin\tTracerPID\tTTY\tCommand\tIO Priority Class\tIO Priority\tNNP\n" ); | ||
495 | output( "s\td\td\td\td\tS\td\td\td\tD\tD\tD\ts\td\ts\ts\td\td\n" ); | 500 | output( "s\td\td\td\td\tS\td\td\td\tD\tD\tD\ts\td\ts\ts\td\td\td\n" ); | ||
496 | } | 501 | } | ||
497 | 502 | | |||
498 | void printProcessCount( const char* cmd ) | 503 | void printProcessCount( const char* cmd ) | ||
499 | { | 504 | { | ||
500 | (void)cmd; | 505 | (void)cmd; | ||
501 | struct dirent* entry; | 506 | struct dirent* entry; | ||
502 | ProcessCount = 0; | 507 | ProcessCount = 0; | ||
503 | rewinddir(procDir); | 508 | rewinddir(procDir); | ||
▲ Show 20 Lines • Show All 179 Lines • Show Last 20 Lines |