Skip to content

Commit d0098eb

Browse files
committed
pgrep: add runstates TraceStopped, Dead, and Idle
1 parent e764d24 commit d0098eb

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/uu/pgrep/src/process.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,26 @@ impl TryFrom<PathBuf> for Teletype {
9696
}
9797
}
9898

99-
/// State or process
99+
/// State of process
100+
/// https://www.man7.org/linux/man-pages//man5/proc_pid_stat.5.html
100101
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
101102
pub enum RunState {
102-
///`R`, running
103+
/// `R`, running
103104
Running,
104-
///`S`, sleeping
105+
/// `S`, sleeping
105106
Sleeping,
106-
///`D`, sleeping in an uninterruptible wait
107+
/// `D`, sleeping in an uninterruptible wait
107108
UninterruptibleWait,
108-
///`Z`, zombie
109+
/// `Z`, zombie
109110
Zombie,
110-
///`T`, traced or stopped
111+
/// `T`, stopped (on a signal)
111112
Stopped,
113+
/// `t`, tracing stop
114+
TraceStopped,
115+
/// `X`, dead
116+
Dead,
117+
/// `I`, idle
118+
Idle,
112119
}
113120

114121
impl Display for RunState {
@@ -119,6 +126,9 @@ impl Display for RunState {
119126
Self::UninterruptibleWait => write!(f, "D"),
120127
Self::Zombie => write!(f, "Z"),
121128
Self::Stopped => write!(f, "T"),
129+
Self::TraceStopped => write!(f, "t"),
130+
Self::Dead => write!(f, "X"),
131+
Self::Idle => write!(f, "I"),
122132
}
123133
}
124134
}
@@ -133,6 +143,9 @@ impl TryFrom<char> for RunState {
133143
'D' => Ok(Self::UninterruptibleWait),
134144
'Z' => Ok(Self::Zombie),
135145
'T' => Ok(Self::Stopped),
146+
't' => Ok(Self::TraceStopped),
147+
'X' => Ok(Self::Dead),
148+
'I' => Ok(Self::Idle),
136149
_ => Err(io::ErrorKind::InvalidInput.into()),
137150
}
138151
}
@@ -476,6 +489,9 @@ mod tests {
476489
);
477490
assert_eq!(RunState::try_from("T").unwrap(), RunState::Stopped);
478491
assert_eq!(RunState::try_from("Z").unwrap(), RunState::Zombie);
492+
assert_eq!(RunState::try_from("t").unwrap(), RunState::TraceStopped);
493+
assert_eq!(RunState::try_from("X").unwrap(), RunState::Dead);
494+
assert_eq!(RunState::try_from("I").unwrap(), RunState::Idle);
479495

480496
assert!(RunState::try_from("G").is_err());
481497
assert!(RunState::try_from("Rg").is_err());

0 commit comments

Comments
 (0)