--- 
canonical: 'https://mwop.net/blog/2026-12-02-timing-long-processes.html'
title: 'Timing Long-Running Processes on Linux'
author: "[Matthew Weier O'Phinney](https://mwop.net)"
created: '2026-12-02T10:47:03-06:00'
updated: '2026-12-02T10:47:03-06:00'
tags:
  - linux
  - til

---
In my homelab, I've been setting up a number of scheduled jobs for things like backups, RAID consistency scans, and more. Some of these take longer than others, and some will actively impact others if they run at the same time. In some cases, I'd put in timeouts... and am hitting them, because I underestimated the time required.

So, I needed to determine how long they were running. And I realized this _after_ I'd started a process, so I needed to learn how to identify when it started, and when it would end.





Finding when it starts is the easy part. The `ps` utility has a number of options for emitting custom fields in its output. I first ran `ps` in order to identify the PID I was interested in, and then ran:

```bash
ps -eo pid,stime -p <pid>
```

The "-p" flag lets you specify one or more PIDs for which to return information, while the "-o" flag  allows you to specify the fields to return in the formatted output. Here, I'm returning the PID and the start time.

Now for the harder part: I wanted to know when the process ended, without having to sit there watching the CLI for it to finish. (This was a good decision; this particular process took 5.5 _hours_!)

The `/proc` filesystem holds a directory per open process, and this directory has a bunch of information ­— where the command is running, the full commandline used to invoke the process, UID and GID under which it run, and a ton more. The main thing is: I can _watch the directory_, and when it goes away, the process is complete. That looks like this:

```bash
# In the Fish shell:
while test -d /proc/<pid>; sleep 1; end; date '+%Y-%m-%d %H:%M:%S %Z'
# In bash:
while test -d /proc/<pid>; do sleep 1; done; date '+%Y-%m-%d %H:%M:%S %Z'
```

I was able to run this, and then walk away from that terminal, and later get an idea of how long the process took.

#### PID re-use

Technically, PIDs can be re-used, and the above could be a problem if it's re-used immediately. In practice... I've rarely seen it, particularly since operating systems started extending their PID ranges (in my early years of using Linux, the range often only extended as far as 9999; today, they can be in the six-digit range). If you're worried about it, instead of `test -d /proc/<pid>`, you can use `kill -0 <pid> 2>/dev/null` (the `-0` signal is a no-op, and is just verifying the PID exists). If you do this, however, you have to do it as the user who owns the process, or as root; testing for directory existence does not have that limitation.