--- /dev/null
+#!/bin/bash
+#
+# Calin-Andrei Burloiu, 2011, calin.burloiu@gmail.com
+#
+# This script is used to start delay measurement. It does the following:
+# 1. Start the handle packets script (that is going to wait for SystemTap to start
+# hooking).
+# 2. Starts SystemTap.
+# 3. Waits until a SIGINT is received. When this happens kills the above
+# processes and makes cleanup.
+#
+
+if [ $# != 3 ]; then
+ echo "usage: $0 server_host server_port output_file" >&2
+ exit 1
+fi
+
+host="$1"
+port=$2
+output="$3"
+
+stap_output="stap.log"
+handle_packets_output=/dev/null #"handle-packets.log"
+handle_packets_script="handle-packets.py"
+
+# Called at the end when SIGINT is received.
+cleanup()
+{
+ # Kill handle packets script.
+ kill -s SIGUSR1 $handle_packets_script_pid
+ # Kill SystemTap.
+ kill $stap_pid
+ # Delete stap's output file.
+ rm "$stap_output"
+ echo "Measure Delay Finished."
+}
+
+trap cleanup SIGINT
+
+# Delete stap's output file.
+rm "$stap_output"
+
+# Start handle packets script which sends TCP data and processes stap output.
+python "$handle_packets_script" $host $port "$output" &> "$handle_packets_output" &
+handle_packets_script_pid=$!
+
+# Start SystemTap.
+stap hook.stp -x $handle_packets_script_pid -o "$stap_output" &
+stap_pid=$!
+
+# Wait for the signal.
+sleep 1000000
+