Code to toggle a program Challenge

Write a program that toggles another. Your program should accept exactly two command arguments. Specifically, your two tasks are:


If the names of any running processes are identical to argument one, close them and exit
If the names of zero running processes are named identical to argument one, spawn one with that name, pass it the second command arg, and exit


The life of the spawned process must be completely independent of your own (think Daemon threads in Java, or Background threads in C#). You are responsible for closing programs that you didn't necessarily start in a past life.

Example

Here are two separate examples of how your program might be called.

python YourToggler.py Notepad.exe C:\MyTextFile.txt
java MyToggler.java cmd "echo hello world"


In the first example, if Notepad.exe is currently running, you should close all processes named Notepad.exe. Otherwise, you should start one with the argument C:\MyTextFile.txt.

Assumptions

You can sleep better knowing the following:


The name passed to you will be a valid program
You are not responsible for name discrepancies

If you are asked to find Notepad, you are not responsible for closing Notepad.exe

You will be run with the privileges you need to carry out your duty
Bash+common Linux utilities, 12 or 16 bytes
pkill &quot;$1&quot;||&quot;$@&quot;

If we can assume no whitespace in the program name and arg, then we can drop the quotes for a score of 12:
pkill $1||$@