Aaron
Aaron

Reputation: 45

LINUX How to get the non running PID-s?

I need a shell script to list all the non used(running) pid files.

How can I check if the pid isn't running?

Upvotes: 0

Views: 460

Answers (1)

Isabell Cowan
Isabell Cowan

Reputation: 133

Is this what you're looking for?

#!/bin/bash
while read -d $'\0' -r f; do
  pid="$(cat "$f")"
  if ! ps "$pid" &> /dev/null; then
    echo "$pid"
  fi
done < <(find /run -type f -regextype posix-basic -regex '^.*\.pid$' -print0)

Upvotes: 1

Related Questions