1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use crate::Error;

pub use sysinfo::{Process, ProcessExt, Signal, System, SystemExt};

/// Gets the parent process
pub fn get_parent_process(system: &mut sysinfo::System) -> Result<&Process, Error> {
  let pid = sysinfo::get_current_pid().unwrap();
  system.refresh_process(pid);
  let current_process = system.get_process(pid).ok_or(Error::ParentProcess)?;
  let parent_pid = current_process.parent().ok_or(Error::ParentPid)?;
  let parent_process = system.get_process(parent_pid).ok_or(Error::ParentProcess)?;

  Ok(parent_process)
}