Read the PID from a forward PID file. Returns `None` if the file does not exist or cannot be parsed.
(name: &str, port: u16)
| 75 | /// Read the PID from a forward PID file. Returns `None` if the file does not |
| 76 | /// exist or cannot be parsed. |
| 77 | pub fn read_forward_pid(name: &str, port: u16) -> Option<ForwardPidRecord> { |
| 78 | let path = forward_pid_path(name, port).ok()?; |
| 79 | let contents = std::fs::read_to_string(path).ok()?; |
| 80 | let mut parts = contents.split('\t'); |
| 81 | let pid = parts.next()?.trim().parse().ok()?; |
| 82 | let sandbox_id = parts.next().map(str::to_string); |
| 83 | let bind_addr = parts.next().map(|s| s.trim().to_string()); |
| 84 | Some(ForwardPidRecord { |
| 85 | pid, |
| 86 | sandbox_id, |
| 87 | bind_addr, |
| 88 | }) |
| 89 | } |
| 90 | |
| 91 | /// Check whether a process is alive. |
| 92 | pub fn pid_is_alive(pid: u32) -> bool { |