Created
April 24, 2023 01:52
-
-
Save john-yuan/3ce15f9fb7b3fd3bfc8da821c023b4bc to your computer and use it in GitHub Desktop.
Linux shell script to get pid by process name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
readonly CMD="${@:1}" | |
if [ "$CMD" == "" ] | |
then | |
echo "usage: $0 <command>" | |
exit 1 | |
fi | |
ps --no-headers -ax -o "pid,command" | grep "$CMD" | grep -v "grep $CMD" | awk '{$1=$1};1' | cut -d ' ' -f 1 | grep -v $$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: