Skip to content

Commit 7067bdd

Browse files
Merge pull request #341 from cakebaker/pgrep_add_missing_process_states
pgrep: add runstates `TraceStopped`, `Dead`, and `Idle`
2 parents 4fe7f0b + 16e31d6 commit 7067bdd

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
@@ -98,19 +98,26 @@ impl TryFrom<PathBuf> for Teletype {
9898
}
9999
}
100100

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

116123
impl Display for RunState {
@@ -121,6 +128,9 @@ impl Display for RunState {
121128
Self::UninterruptibleWait => write!(f, "D"),
122129
Self::Zombie => write!(f, "Z"),
123130
Self::Stopped => write!(f, "T"),
131+
Self::TraceStopped => write!(f, "t"),
132+
Self::Dead => write!(f, "X"),
133+
Self::Idle => write!(f, "I"),
124134
}
125135
}
126136
}
@@ -135,6 +145,9 @@ impl TryFrom<char> for RunState {
135145
'D' => Ok(Self::UninterruptibleWait),
136146
'Z' => Ok(Self::Zombie),
137147
'T' => Ok(Self::Stopped),
148+
't' => Ok(Self::TraceStopped),
149+
'X' => Ok(Self::Dead),
150+
'I' => Ok(Self::Idle),
138151
_ => Err(io::ErrorKind::InvalidInput.into()),
139152
}
140153
}
@@ -494,6 +507,9 @@ mod tests {
494507
);
495508
assert_eq!(RunState::try_from("T").unwrap(), RunState::Stopped);
496509
assert_eq!(RunState::try_from("Z").unwrap(), RunState::Zombie);
510+
assert_eq!(RunState::try_from("t").unwrap(), RunState::TraceStopped);
511+
assert_eq!(RunState::try_from("X").unwrap(), RunState::Dead);
512+
assert_eq!(RunState::try_from("I").unwrap(), RunState::Idle);
497513

498514
assert!(RunState::try_from("G").is_err());
499515
assert!(RunState::try_from("Rg").is_err());

0 commit comments

Comments
 (0)