Skip to content

Instantly share code, notes, and snippets.

@henri
Last active January 6, 2026 03:53
Show Gist options
  • Select an option

  • Save henri/da501834117110f614ffdc0f21ea2434 to your computer and use it in GitHub Desktop.

Select an option

Save henri/da501834117110f614ffdc0f21ea2434 to your computer and use it in GitHub Desktop.
long running process bash monitoring process PID and time
#!/usr/bin/env bash
#
# Create a long running process which may be used for experimentation
#
#
# check how long a process is running in seconds
# ps -p <PID> -o etimes=
#
# generic
# ps -p <PID> -o pid,comm,etime
#
# pgrep --full <process name>
#
#
# note : this implimentation has no support yet for catching interupts / signals
#
total_run_time_seconds=0
while true; do
echo "PID $$"
echo "Running... press Ctrl+C to stop"
sleep 60
total_run_time_seconds=$((total_run_time_seconds + 60))
echo " Running for $total_run_time_seconds"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment