# Process validity in Chromium
[base::Process](https://source.chromium.org/chromium/chromium/src/+/main:base/process/process.h;l=65;drc=f3f294fcf7d9c921e328e4c346f53aeb11862a65) is a Chromium expression of a process.
base::Process has [IsValid](https://source.chromium.org/chromium/chromium/src/+/main:base/process/process.h;l=106;drc=f3f294fcf7d9c921e328e4c346f53aeb11862a65) method which aims to check if the process is valid.
So what does "valid" mean?
## IsValid
This class has implementations for each platform.
Let's use [process_posix.cc](https://source.chromium.org/chromium/chromium/src/+/main:base/process/process_posix.cc) as an example implementation in this note.
[Process::IsValid](https://source.chromium.org/chromium/chromium/src/+/main:base/process/process_posix.cc;l=279;drc=740b81bcdf6eb036bbe94bdda3841979ae9b2d88) implementation on Posix is just checking whether `process_` is kNullProcessHandle or not.
[`process_`](https://source.chromium.org/chromium/chromium/src/+/main:base/process/process.h;l=295;drc=d4a7d3fb6f5100019d6153d5cf00c60f06b1d0a2) is [ProcessHandle](https://source.chromium.org/chromium/chromium/src/+/main:base/process/process_handle.h) in ChromeOS platform.
```cpp=
typedef pid_t ProcessHandle;
typedef pid_t ProcessId;
const ProcessHandle kNullProcessHandle = 0;
const ProcessId kNullProcessId = 0;
```
ProcessHandle in Posix is just a PID.
And [kNullProcessHandle](https://source.chromium.org/chromium/chromium/src/+/main:base/process/process_handle.h;l=46;drc=e4622aaeccea84652488d1822c28c78b7115684f) is 0 which represents a invalid state of process.
`process_` is set to kNullProcessHandle on multiple locations.
On construction, [base::Process](https://source.chromium.org/chromium/chromium/src/+/main:base/process/process.h;l=69;drc=f3f294fcf7d9c921e328e4c346f53aeb11862a65) gets ProcessHandle as an argument, and kNullProcessHandle is set by default.
Therefore, `some_process_ = base::Process()` means `process_` is reset.
Also on [Release](https://source.chromium.org/chromium/chromium/src/+/main:base/process/process_posix.cc;l=300;drc=740b81bcdf6eb036bbe94bdda3841979ae9b2d88) and [Close](https://source.chromium.org/chromium/chromium/src/+/main:base/process/process_posix.cc;l=313;drc=740b81bcdf6eb036bbe94bdda3841979ae9b2d88).
As you can see here, `process_` here is set to kNullProcessHandle on closing or releasing, [Process::IsValid](https://source.chromium.org/chromium/chromium/src/+/main:base/process/process_posix.cc;l=279;drc=740b81bcdf6eb036bbe94bdda3841979ae9b2d88) refers to `process_` value and returns true if `process_` is not equal to kNullProcessHandle.
## Terminate
How about Terminate?
[Terminate](https://source.chromium.org/chromium/chromium/src/+/main:base/process/process_posix.cc;l=320;drc=740b81bcdf6eb036bbe94bdda3841979ae9b2d88) is a method to termionates the process with extreme prejudice.
It sends [kill](https://source.chromium.org/chromium/chromium/src/+/main:base/process/process_posix.cc;l=340;drc=740b81bcdf6eb036bbe94bdda3841979ae9b2d88) signal to force termination.
And then [WaitForExitWithTimeout](https://source.chromium.org/chromium/chromium/src/+/main:base/process/process_posix.cc;l=363;drc=d4a7d3fb6f5100019d6153d5cf00c60f06b1d0a2) until `timeout` length.
Looking through this path, it actually does not modify `process_` value.
So Terminate does not reset `process_` to kNullProcessHandle.
`process_.IsValid()` does not work as a flag to check if the process is running.
TL;DR; base::Process object is not tied to its lifetime. The process may be killed while this object still alive and claim it's valid.