eminence / procfs

Rust library for reading the Linux procfs filesystem
Other
367 stars 106 forks source link

Zombie processes are considered alive #197

Closed Nukesor closed 2 years ago

Nukesor commented 2 years ago

Hi!

It looks like the behavior of Process::is_alive has changed. I'm not 100% sure if this was a deliberate change or a regression. As it wasn't documented in the Changelog, I assumed that this is indeed a bug.

Previously, Zombie processes weren't detected as alive. This however changed in v0.13.

A minimal reproducable example can be found over here: https://github.com/Nukesor/Debug/tree/procfs-zombie-process

git clone git@github.com:Nukesor/Debug
cd Debug
git switch procfs-zombie-process
cargo run

The example spawns a sleep 2 and checks the is_alive function and the current process' state:

Process 402069 is alive with state Running
Process 402069 is alive with state Sleeping
Process 402069 is alive with state Sleeping
Process 402069 is alive with state Sleeping
Process 402069 is alive with state Zombie
Process 402069 is alive with state Zombie

From what I gathered, Zombie processes shouldn't be considered alive.

This change in behavior was introduced in v0.13.

v0.12 worked as expected:

Process 403784 is alive with state Running
Process 403784 is alive with state Sleeping
Process 403784 is alive with state Sleeping
Process 403784 is alive with state Sleeping
Process 403784 is dead with state Zombie
Process 403784 is dead with state Zombie
eminence commented 2 years ago

Hi! You're absolutely right. This is a regression, sorry about that.

Taking this opportunity to think about what this API should do: is there any scenario in which a zombie process should be considered "alive"? I can't think of one. And if someone wants to distinguish a zombie from a fully reaped process, I think they can just check if its state is Zombie.

If you want to make the PR for this, please feel free! Otherwise I'll make the fix and then I think I'll backport it to the 0.13 release as well

Nukesor commented 2 years ago

Thanks for the quick response and no worries :)

I just took a quick look at the other states and from what I understand only Zombie and Dead are considered dead. I also agree that one has to look at the current state, if one wants to determine whether a process is Dead or a Zombie. The same goes for all other alive states.

It would be great, if you could take care of fixing this! I'm currently quite busy maintaining my own projects :sweat:.

Personally, I also don't need this fix in a timely manner. v0.12 is still working perfectly fine!

Thanks in advance!

eminence commented 2 years ago

No worries. I know that some people like to fix bugs that they report, so I wanted to give that opportunity to you. But I think you correctly understood that the offer was with no obligation at all :)

I'll work on the fix this week. Thanks again for reporting the issue!

eminence commented 2 years ago

This has been fixed in v0.13.3 and v0.14.1