Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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