2 # Functions for parsing openbsd ps output
6 local($pcmd, $line, $i, %pidmap, @plist);
7 $pcmd = @_ ? "-p $_[0]" : "";
8 open(PS, "ps -axwwww -o pid,ppid,user,vsz,%cpu,time,nice,tty,ruser,rgid,pgid,lstart,lim,command $pcmd |");
9 for($i=0; $line=<PS>; $i++) {
11 if ($line =~ /ps -axwwww/ || $line =~ /^\s*PID/) { $i--; next; }
12 $line =~ /^\s*(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+([\d\.]+)\s+(\S+)\s+(-?\d+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(-|\S+\s+\S+\s+\d+\s+\S+\s+\d+|\d+)\s+(\S+)\s+(.*)$/;
14 $plist[$i]->{"pid"} = $1;
15 $plist[$i]->{"ppid"} = $2;
16 $plist[$i]->{"user"} = $3;
17 $plist[$i]->{"size"} = "$4 kB";
18 $plist[$i]->{"cpu"} = $5;
19 $plist[$i]->{"time"} = $6;
20 $plist[$i]->{"nice"} = $7;
21 $plist[$i]->{"_tty"} = $8;
22 $plist[$i]->{"_ruser"} = $9;
23 $plist[$i]->{"_rgroup"} = getgrgid($10);
24 $plist[$i]->{"_pgid"} = $11;
25 $plist[$i]->{"_lstart"} = $12;
26 $plist[$i]->{"_lim"} = $13 eq "-" ? "Unlimited" : $13;
27 $plist[$i]->{"args"} = $14;
33 # renice_proc(pid, nice)
36 return undef if (&is_readonly_mode());
37 local $out = &backquote_logged("renice $_[1] -p $_[0] 2>&1");
38 if ($?) { return $out; }
42 foreach $ia (keys %text) {
43 if ($ia =~ /^freebsd(_\S+)/) {
44 $info_arg_map{$1} = $text{$ia};
48 @nice_range = (-20 .. 20);
50 $has_fuser_command = 0;
53 # Returns the filehandles and names for a pty and tty
58 @ptys = map { "/dev/$_" } (grep { /^pty/ } readdir(DEV));
61 foreach $pty (@ptys) {
62 open(PTY, "+>$pty") || next;
65 open(TTY, "+>$tty") || next;
66 local $old = select(PTY); $| = 1;
67 select(TTY); $| = 1; select($old);
68 return (*PTY, *TTY, $pty, $tty);