2

I'm debugging a networking project, which involves interacting of 3 programs, ie a server, two different clients. However I find it difficult to start and stop them for debugging. Some methods I have tried so far:

  • Start 3 terminals. Run ./server, ./client1, ./client2. The problem with this method is I need to switch back and forth between windows.

  • Start 1 terminal. Put these in a script: ./server &;./client1 &;./client2 &. Run the script. The problem with this method is killing the processes after debugging is hard. Need to look up PID and type kill <PID>.

Is there a better way to do this? How do people usually debug in that situation?

1

Make something like this your launch script:

./server & server_pid=$!
./client1 & client1_pid=$!
./client2 & client2_pid=$!
echo 'kill "$@"' "$server_pid $client1_pid $client2_pid" >.kill.sh

And call ./kill.sh to kill all the processes. The key point is to use $! to retrieve the PID of the last backgrounded command, You may prefer other methods for storing it and later making use of it.

  • Why did you write the dot in the beginning of the filename? .kill.sh – rahmu Oct 21 '11 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.