Check-in [4ee619220a]
Overview
SHA1:4ee619220ada40324e9911b6c00f4081ea3f5dde
Date: 2014-10-30 19:16:56
User: rkeene
Comment:Added "ps" command
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2014-11-03
16:34
[9b491cd779] Implemented rlimit and klogctl (user: rkeene, tags: trunk)
2014-10-30
19:16
[4ee619220a] Added "ps" command (user: rkeene, tags: trunk)
15:52
[b37f8d7df9] Added some basic UNIX commands (user: rkeene, tags: trunk)
Changes

Modified tuapi.tcl from [0e870c7074] to [01f421e4ee].

   500    500   			puts ""
   501    501   		}
   502    502   	}
   503    503   
   504    504   	proc ::modprobe args {
   505    505   		::tuapi::modprobe {*}$args
   506    506   	}
          507  +
          508  +	proc ::ps {} {
          509  +		set format {%-6s %5s %5s %3s %5s %-6s %8s %s}
          510  +		puts [format $format UID PID PPID C STIME TTY TIME CMD]
          511  +		foreach pid [lsort -dictionary [glob -nocomplain -directory /proc -tails {[0-9]*}]] {
          512  +			if {![string is integer $pid]} {
          513  +				continue
          514  +			}
          515  +
          516  +			set procfile [file join /proc $pid]
          517  +
          518  +			unset -nocomplain pidinfo
          519  +			catch {
          520  +				file stat $procfile pidinfo
          521  +			}
          522  +
          523  +			if {![info exists pidinfo]} {
          524  +				continue
          525  +			}
          526  +
          527  +			set pidinfo(pid) $pid
          528  +			set pidinfo(ppid) ?
          529  +			set pidinfo(cpuutil) ?
          530  +			set pidinfo(starttime) ?
          531  +			set pidinfo(tty) ?
          532  +			set pidinfo(cputime) ?
          533  +			set pidinfo(cmd) ""
          534  +
          535  +			unset -nocomplain fd
          536  +			catch {
          537  +				set fd [open [file join $procfile cmdline]]
          538  +			}
          539  +			if {[info exists fd]} {
          540  +				set pidinfo(cmd) [string trim [join [split [read $fd] "\0\n\r"]]]
          541  +				close $fd
          542  +				unset fd
          543  +			}
          544  +			if {![info exists pidinfo(cmd)] || $pidinfo(cmd) == ""} {
          545  +				catch {
          546  +					set fd [open [file join $procfile comm]]
          547  +				}
          548  +				if {[info exists fd]} {
          549  +					set pidinfo(cmd) "\[[string trim [join [split [read $fd] "\0\n\r"]]]\]"
          550  +					close $fd
          551  +				}
          552  +			}
          553  +
          554  +			puts [format $format $pidinfo(uid) $pidinfo(pid) $pidinfo(ppid) $pidinfo(cpuutil) $pidinfo(starttime) $pidinfo(tty) $pidinfo(cputime) $pidinfo(cmd)]
          555  +		}
          556  +	}
   507    557   }