diff --git a/src/ffiselect/mod.rs b/src/ffiselect/mod.rs new file mode 100644 index 000000000..6dbc6368d --- /dev/null +++ b/src/ffiselect/mod.rs @@ -0,0 +1,18 @@ +use crate::utils::oom::set_oom_score_adj; + +pub fn spawn_task(task: Task) -> Result { + let child = Command::new(task.program) + .args(&task.args) + // ... other command setup ... + .spawn()?; + + // Set high OOM score for non-PoSt tasks + if !task.is_post_task() { + if let Err(e) = set_oom_score_adj(child.id() as i32, 900) { + log::warn!("Failed to set OOM score adjustment: {}", e); + // Continue execution even if setting OOM score fails + } + } + + Ok(child) +} \ No newline at end of file diff --git a/src/utils/oom.rs b/src/utils/oom.rs new file mode 100644 index 000000000..3a60d94ff --- /dev/null +++ b/src/utils/oom.rs @@ -0,0 +1,8 @@ +use std::fs; +use std::io; +use std::path::Path; + +pub fn set_oom_score_adj(pid: i32, score: i16) -> io::Result<()> { + let path = format!("/proc/{}/oom_score_adj", pid); + fs::write(Path::new(&path), score.to_string()) +} \ No newline at end of file