im very new to Linux and i'm trying to create a script to launch a server (ICAtariControllerServer) alongside the client which is my game (Circus_Interstellar) but so far when i exit the game the server is still running. I want the server to launch, put itself in the background, then launch my game in the foreground and if that game exits in anyway (hitting the exit button in game, crashing, exiting via terminal, ect.) I want the server to notice that and exit as well.
Here is some code I'm trying to use, however even though it successfully launches both programs, with the server in the background and game in the foreground, i cant get the server to exit when the game ends.
# Function to start the server process
start_server() {
./server/ICAtariControllerServer &
server_pid=$!
# disown
}
# Function to start the client process
start_client() {
./Circus_Interstellar
sleep 5 &
client_pid=$!
# disown
}
# Function to kill the server process
kill_server() {
kill -9 "$1"
}
# Function to kill the client process
kill_client() {
kill -9 "$1"
}
# Trap signals and clean up processes
trap "kill_client $client_pid; kill_server $server_pid; exit" SIGINT SIGTERM EXIT
# Main script logic
start_server
start_client
# Wait for the client process to exit
wait $client_pid
This is the first time ive ever posted a question here and i'm very new to linux (just need to learn enough to work on Atari VCS) so bear with me.
Thank you!