manutd manutd - 1 year ago 121
Java Question

Java process executor in Mac OS

I am using the below code to close all the FireFox instances in a windows machine. Can this same code used in Mac machine? If not what will be the best approach?

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

Answer Source

Can this same code used in Mac machine?


But this will work:

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

Explanation of 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download