Skip to content

Instantly share code, notes, and snippets.

@kkleidal
Created January 6, 2015 15:30
Show Gist options
  • Save kkleidal/30f7c2a170445a261155 to your computer and use it in GitHub Desktop.
Save kkleidal/30f7c2a170445a261155 to your computer and use it in GitHub Desktop.
PID of Process BASH
#!/bin/bash
# Get the PID of a process matching the pattern specified
# in the first argument as displayed in ps axf
# This line can be used in any script, just replace $1 with the match string:
PID=$(ps axf | grep "$1" | grep -v grep | awk '{print $1}' | head -n1)
echo "$PID"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment