Skip to content

pidfile

Functions

  • mtime - Return pidfile modification time if the file exists.
  • read - Read a pid file.
  • remove - Remove a pid file if present.
  • write - Write a pid file, publishing it by rename.

Function

Return pidfile modification time if the file exists.

Returns filesystem metadata errors other than not-found.

fn mtime(path: &std::path::Path) -> crate::error::Result<Option<std::time::SystemTime>>

Function

Read a pid file.

Returns filesystem errors other than not-found, or an error unless the file contains one canonical non-zero decimal process ID followed by one newline.

fn read(path: &std::path::Path) -> crate::error::Result<Option<crate::process_id::UserProcessId>>

Function

Remove a pid file if present.

Returns filesystem errors other than not-found.

fn remove(path: &std::path::Path) -> crate::error::Result<()>

Function

Write a pid file, publishing it by rename.

The pid is written to a flushed temporary file in the same directory and then renamed over path. On Unix the rename is atomic and the parent directory is flushed afterwards, so a concurrent reader observes either the previous file or the complete new one, and the replacement survives a crash. On Windows the rename goes through MoveFileEx with replace semantics, which still avoids a truncate/append window but is not guaranteed to be atomic against a reader holding the destination open.

Returns filesystem errors.

fn write(path: &std::path::Path, pid: crate::process_id::UserProcessId) -> crate::error::Result<()>