From c14a6f943b2d43c3be89011a75d9f5153824e9ff Mon Sep 17 00:00:00 2001 From: prplV Date: Wed, 13 Nov 2024 15:15:39 +0300 Subject: [PATCH] docs: prcs --- src/utils/prcs.rs | 112 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 108 insertions(+), 4 deletions(-) diff --git a/src/utils/prcs.rs b/src/utils/prcs.rs index f76a68e..8cc865b 100644 --- a/src/utils/prcs.rs +++ b/src/utils/prcs.rs @@ -1,10 +1,22 @@ use crate::options::structs::CustomError; use log::{error, warn}; -use std::io; use std::process::{Command, Output}; use std::sync::Arc; use tokio::time::Duration; +/// # Fn `get_pid` +/// ## for initializing process of unstoppable grubbing metrics. +/// +/// *input* : `&str` +/// +/// *output* : `None` if cant get process PID | `Some(Output)` on success +/// +/// *initiator* : fn `is_frozen`, fn `utils::files::file_handler`, fn `utils::files::service_handler` +/// +/// *managing* : process name +/// +/// *depends on* : - +/// pub async fn get_pid(name: &str) -> Option { let name = Arc::new(name.to_string()); let res = @@ -20,8 +32,20 @@ pub async fn get_pid(name: &str) -> Option { None } } -// ! can be with bug !!! -// * APPROVED + +/// # Fn `is_active` +/// ## for checking process's activity state +/// +/// *input* : `&str` +/// +/// *output* : `true` if process running | `false` if not +/// +/// *initiator* : fn `utils::files::file_handler`, fn `utils::files::service_handler` +/// +/// *managing* : process name +/// +/// *depends on* : - +/// pub async fn is_active(name: &str) -> bool { let arc_name = Arc::new(name.to_string()); tokio::task::spawn_blocking(move || { @@ -38,7 +62,19 @@ pub async fn is_active(name: &str) -> bool { .unwrap() } -// T is for stopped processes +/// # Fn `is_frozen` +/// ## for checking process's hibernation state +/// +/// *input* : `&str` +/// +/// *output* : `true` if process is frozen | `false` if not +/// +/// *initiator* : fn `utils::files::file_handler`, fn `utils::files::service_handler` +/// +/// *managing* : process name +/// +/// *depends on* : fn `get_pid` +/// pub async fn is_frozen(name: &str) -> bool { let temp: Output; if let Some(output) = get_pid(name).await { @@ -66,6 +102,20 @@ pub async fn is_frozen(name: &str) -> bool { .unwrap() } } + +/// # Fn `terminate_process` +/// ## for stop current process +/// +/// *input* : `&str` +/// +/// *output* : - +/// +/// *initiator* : fn `utils::files::file_handler`, fn `utils::files::service_handler`, fn `utils::run_daemons` +/// +/// *managing* : process name +/// +/// *depends on* : - +/// pub async fn terminate_process(name: &str) { let _ = Command::new("pkill") .arg(name) @@ -76,6 +126,19 @@ pub async fn terminate_process(name: &str) { }); } +/// # Fn `terminate_process` +/// ## for freeze/hibernate current process +/// +/// *input* : `&str` +/// +/// *output* : - +/// +/// *initiator* : fn `utils::run_daemons` +/// +/// *managing* : process name +/// +/// *depends on* : - +/// pub async fn freeze_process(name: &str) { let _ = Command::new("pkill") .args(["-STOP", name]) @@ -85,6 +148,20 @@ pub async fn freeze_process(name: &str) { std::process::exit(101); }); } + +/// # Fn `unfreeze_process` +/// ## for unfreeze/hibernate current process +/// +/// *input* : `&str` +/// +/// *output* : - +/// +/// *initiator* : fn `utils::run_daemons` +/// +/// *managing* : process name +/// +/// *depends on* : - +/// pub async fn unfreeze_process(name: &str) { let _ = Command::new("pkill") .args(["-CONT", name]) @@ -94,12 +171,39 @@ pub async fn unfreeze_process(name: &str) { std::process::exit(101); }); } + +/// # Fn `restart_process` +/// ## for restarting current process +/// +/// *input* : `&str`, &str +/// +/// *output* : - +/// +/// *initiator* : fn `utils::run_daemons` +/// +/// *managing* : process name and path to its exec file +/// +/// *depends on* : fn `start_process`, fn `terminate_process` +/// pub async fn restart_process(name: &str, path: &str) -> Result<(), CustomError> { terminate_process(name).await; tokio::time::sleep(Duration::from_millis(100)).await; start_process(name, path).await } +/// # Fn `start_process` +/// ## for starting current process +/// +/// *input* : `&str`, &str +/// +/// *output* : - +/// +/// *initiator* : fn `restart_process` +/// +/// *managing* : process name and path to its exec file +/// +/// *depends on* : - +/// pub async fn start_process(name: &str, path: &str) -> Result<(), CustomError> { // let runsh = format!("{} {}", "exec", path); let mut command = Command::new(path);