Created
June 4, 2022 21:09
-
-
Save santaklouse/03fa8f5c67fa44ae7a420abaab2c8be1 to your computer and use it in GitHub Desktop.
get pids of process names
This file contains hidden or 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
| function pidsof() { | |
| pids=(`pgrep "$1"`, `pidof "$1"`, `ps -Ac | grep -m1 '"$1"\$' | awk '{print \$1}'`) | |
| pids=$piods|tr ',' ' ' | |
| echo pids | |
| # | |
| # strings=(`pgrep "$a"`, `pidof "$a"`, `ps -Ac | grep -m1 '"$a"\$' | awk '{print \$1}'`) | |
| # | |
| # pids=() | |
| # for i in "${!strings[@]}" ; do | |
| # #echo "${strings[$i]}" | |
| # cmd="${strings[$i]/ARG/"$a"}"; | |
| # #echo "$cmd" | |
| # pids+="$(echo $cmd)"|tr ',' '\n'; | |
| # echo $(echo $cmd|tr ',' '\n') | |
| # | |
| # done | |
| # | |
| # | |
| # | |
| # pids=($pids) | |
| # | |
| # echo $pids | |
| # echo ${pids[@]} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment