import os with open("./pids.txt", "r") as f: for line in f: os.system("sudo kill " + line)