open Virt_mem_gettext.Gettext
open Virt_mem_utils
-open Virt_mem_mmap
-
-let usage = s_"NAME
- virt-ps - process listing command for virtual machines
-
-SUMMARY
- virt-ps [-options] [domains]
-
-DESCRIPTION
- virt-ps prints a process listing for virtual machines running under
- libvirt."
-
-let debug, images = Virt_mem.start usage
+open Virt_mem_types
+
+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 ~needs_tasks:true ~run