Set the pid of a searched running process (ps -ea | grep <search>}) in shell

StackOverflow https://stackoverflow.com/questions/17219304

  •  01-06-2022
  •  | 
  •  

문제

I am making a shell script where I run a process and I am searching for that process like this ps -ea | grep <search_term> and I can find that process fine, but I want to set the pid of that process to a variable in my shell script, then wait until that process is finished. This is the type of thing I want:

PID= (returned and parsed value of "ps -ea | grep <search_term>")
echo $PID
wait $PID
도움이 되었습니까?

해결책

PID=$(ps -ea | awk '/<search_term>/,NF=1')

Shell script to get the process ID on Linux

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top