X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=ps%2Fvirt_ps.ml;h=07e5e76bba4b9fb37abf2dccd100077a7adce182;hb=347ea607fd2fa271c94a21a48eb4888e688fcafb;hp=4c995d8f2b7e4917f1ca974431544d90542c6f7f;hpb=b70c967911e197b74d6d7ad98e3df9240d82572f;p=virt-mem.git diff --git a/ps/virt_ps.ml b/ps/virt_ps.ml index 4c995d8..07e5e76 100644 --- a/ps/virt_ps.ml +++ b/ps/virt_ps.ml @@ -21,13 +21,35 @@ open Printf open Virt_mem_gettext.Gettext open Virt_mem_utils -open Virt_mem_mmap +open Virt_mem_types -let run debug images = () +open Kernel + +let run debug { addrmap = addrmap } = + (* Grab all the task_struct structures. *) + let tasks = AddrMap.fold ( + fun _ v tasks -> + match v with + | _, Some (_, _, Task_struct task) -> task :: tasks + | _ -> tasks + ) addrmap [] in + + (* Sort tasks by PID. *) + let cmp { task_struct_pid = p1 } { task_struct_pid = p2 } = compare p1 p2 in + let tasks = List.sort cmp tasks in + + printf " PID STAT COMMAND\n"; + + List.iter ( + fun { task_struct_pid = pid; task_struct_comm = comm } -> + let comm = truncate_c_string comm in + printf "%5Ld %s\n" pid comm + ) tasks let summary = s_"list processes in virtual machine" let description = s_"\ virt-ps prints a process listing for virtual machines running under libvirt." -let () = Virt_mem.register "ps" summary description true run +let () = + Virt_mem.register "ps" summary description ~needs_tasks:true ~run