Getting PID of process in Shell Script
问题 I am writing one shell script and I want to get PID of one process with name as "ABCD". What i did was : process_id=`/bin/ps -fu $USER|grep "ABCD"|awk '{print $2}'` This gets PID of two processes i.e. of process ABCD and the GREP command itself what if I don't want to get PID of GREP executed and I want PID only of ABCD process? Please suggest. 回答1: Just grep away grep itself! process_id=`/bin/ps -fu $USER| grep "ABCD" | grep -v "grep" | awk '{print $2}'` 回答2: Have you tried to use pidof ABCD