- 論壇徽章:
- 0
|
本帖最后由 sjdy521 于 2014-05-04 17:43 編輯
回復(fù) 4# kingfighters
自己寫來寫去不如用現(xiàn)成的模塊,相當(dāng)于自己寫了個(gè)ps命令,這樣真的有意思嗎。。- # A cheap and sleazy version of ps
- use Proc::ProcessTable;
- $FORMAT = "%-6s %-10s %-8s %-24s %s\n";
- $t = new Proc::ProcessTable;
- printf($FORMAT, "PID", "TTY", "STAT", "START", "COMMAND");
- foreach $p ( @{$t->table} ){
- printf($FORMAT,
- $p->pid,
- $p->ttydev,
- $p->state,
- scalar(localtime($p->start)),
- $p->cmndline);
- }
- # Dump all the information in the current process table
- use Proc::ProcessTable;
- $t = new Proc::ProcessTable;
- foreach $p (@{$t->table}) {
- print "--------------------------------\n";
- foreach $f ($t->fields){
- print $f, ": ", $p->{$f}, "\n";
- }
- }
復(fù)制代碼 |
|