diff --git a/src/uu/vmstat/src/vmstat.rs b/src/uu/vmstat/src/vmstat.rs index 38619a7..75d11c8 100644 --- a/src/uu/vmstat/src/vmstat.rs +++ b/src/uu/vmstat/src/vmstat.rs @@ -26,6 +26,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app().try_get_matches_from(args)?; #[cfg(target_os = "linux")] { + if matches.get_flag("forks") { + return print_forks(); + } if matches.get_flag("stats") { return print_stats(); } @@ -83,6 +86,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { Ok(()) } +#[cfg(target_os = "linux")] +fn print_forks() -> UResult<()> { + let data = get_stats(); + + let fork_data = data.last().unwrap(); + println!("{:>13} {}", fork_data.1, fork_data.0); + + Ok(()) +} + #[cfg(target_os = "linux")] fn print_stats() -> UResult<()> { let data = get_stats(); @@ -177,10 +190,13 @@ pub fn uu_app() -> Command { .required(false) .value_parser(value_parser!(u64)), arg!(-a --active "Display active and inactive memory"), - // arg!(-f --forks "switch displays the number of forks since boot"), - arg!(-m --slabs "Display slabinfo"), + arg!(-f --forks "switch displays the number of forks since boot") + .conflicts_with_all(["slabs", "stats", /*"disk", "disk-sum", "partition"*/]), + arg!(-m --slabs "Display slabinfo") + .conflicts_with_all(["forks", "stats", /*"disk", "disk-sum", "partition"*/]), arg!(-n --"one-header" "Display the header only once rather than periodically"), - arg!(-s --stats "Displays a table of various event counters and memory statistics"), + arg!(-s --stats "Displays a table of various event counters and memory statistics") + .conflicts_with_all(["forks", "slabs", /*"disk", "disk-sum", "partition"*/]), // arg!(-d --disk "Report disk statistics"), // arg!(-D --"disk-sum" "Report some summary statistics about disk activity"), // arg!(-p --partition "Detailed statistics about partition"), diff --git a/tests/by-util/test_vmstat.rs b/tests/by-util/test_vmstat.rs index b48c240..6ff26c3 100644 --- a/tests/by-util/test_vmstat.rs +++ b/tests/by-util/test_vmstat.rs @@ -19,6 +19,11 @@ fn test_invalid_arg() { new_ucmd!().arg("--definitely-invalid").fails().code_is(1); } +#[test] +fn test_conflict_arg() { + new_ucmd!().args(&["-s", "-m"]).fails().code_is(1); +} + #[test] fn test_invalid_number() { new_ucmd!().arg("-1").fails().code_is(1);