Java Mac OS 中的进程执行器

Java process executor in Mac OS

我正在使用以下代码关闭 windows 机器中的所有 FireFox 实例。可以在 Mac 机器中使用相同的代码吗?如果不是,最好的方法是什么?

Runtime.getRuntime().exec("taskkill /F /IM FireFox.exe");

Can this same code used in Mac machine?

没有。

但这行得通:

Runtime.getRuntime().exec("pgrep 'firefox' | xargs kill");

pgrep 'firefox' | xargs kill

的解释

pgrep 'firefox' - find all process ids that match processes having firefox in their name.

| xargs kill - Pass all the process IDs found from pgrep as input to the kill command.