#!/bin/python import os import sys import signal SOURCE_PATH = os.path.join(os.path.dirname(__file__), "../swingmusic/") os.chdir(SOURCE_PATH) # We need to find the swingmusic binary if not (os.path.exists(SOURCE_PATH)): print("[FATAL] Could not find swingmusic source in path: " + SOURCE_PATH) sys.exit(1) print("[OK] Swingmusic source found in path: " + SOURCE_PATH) pid = os.fork() # pid greater than 0 represents # the parent process if pid > 0 : print("I am parent process:") print("Process ID:", os.getpid()) print("Child's process ID:", pid) os.chdir("../swingmusic-desktop") os.system("yarn start .") # Terminating the child when we are done (not gracefully: it has to stop) os.kill(pid, signal.SIGINT) print("Bye!") # pid equal to 0 represents # the created child process else : print("\nI am child process:") print("Process ID:", os.getpid()) print("Parent's process ID:", os.getppid()) os.system("./run") exit(0) # Running the binary and getting the pid pid = subprocess.Popen([BINARY_PATH]).pid print("[OK] Swingmusic started with pid: " + str(pid)) # Running yarn run . os.system("yarn start .") # Kill the binary process os.kill(pid, signal.SIGTERM) print("[OK] Swingmusic stopped (theoretically) with pid: " + str(pid))