--- unity.orig 2014-05-30 12:48:50.230610272 +0100 +++ unity.patched 2014-05-30 12:46:26.167471521 +0100 @@ -100,7 +100,19 @@ # kill a previous compiz if was there (this is a hack as compiz can # sometimes get stuck and not exit on --replace) - subprocess.call (["pkill", "-9", "compiz"]) + display = "DISPLAY=" + os.environ["DISPLAY"] + pids = [pid for pid in os.listdir("/proc") if pid.isdigit()] + + for pid in pids: + try: + pid_path = os.path.join("/proc", pid) + cmdline = open(os.path.join(pid_path, "cmdline"), "rb").read() + if "compiz" in str(cmdline): + compiz_env = open(os.path.join(pid_path, "environ"), "rb").read() + if display in compiz_env: + subprocess.call (["kill", "-9", pid]) + except IOError: + continue # shell = True as it's the simpest way to | tee. # In this case, we need a string and not a list