ps aux | grep python | awk '{print $2}' | xargs kill -9Shared by Kim Ji-seong from Naver Boostcamp AI Tech 2nd cohort.
- The pipe ( | ) passes the output of the preceding command to the next.
ps auxretrieves information about all running processes.grep pythonfilters for lines containing “python”.awk '{print $2}'extracts only the second column, which is the PID.- awk blog
- awk can select fields and records.
- Here it prints the content of the 2nd field.
xargs kill -9kills all the extracted PIDs.- xargs blog
- xargs uses piped input as arguments for the given command.
- The awk output becomes the arguments for kill -9.