Lots of piping!


ps -ef |egrep lac.*python3|sed -r "s/lac2([^0-9])+([0-9]+).*/\2/"|xargs sudo renice 10

Today I needed to lower the run priority of a load of jobs running on one of my linux boxes, and this needed the above command. I was quite please with it, four commands, each piping output to the next:

ps-ef lists the running processes on the system

egrep… filters them to python3 jobs owned by a particular user

sed… strips out the process IDs from the lines for those jobs

xargs… turns each of those process IDs into an argument for “renice” which increases each┬áprocesses’ niceness (that is, lowers its priority)

Beautiful.

Leave a Comment

Your email address will not be published.