By using pgrep python
i can filter processes by PID:
JavaScript
x
[@~]$ pgrep python
725886
726128
726379
726816
732699
757708
769148
How can I kill first n processes in one line of code?
Advertisement
Answer
Filter and pass to kill.
JavaScript
pgrep python | head -n $n | xargs kill