Save PID:
./endlessloop & endlessloop_pid=$!
sleep 1
kill "$endlessloop_pid"
You can also check if the process continues to work with kill -0:
if kill -0 "$endlessloop_pid"; then
echo "Endlessloop is still running"
fi
... and storing the contents in a variable means that it scales to several processes:
endlessloop_pids=( )
./endlessloop & endlessloop_pids+=( "$!" )
./endlessloop & endlessloop_pids+=( "$!" )
kill "${endlessloop_pids[@]}"
. BashFAQ # 68: " ( -) N ?"
ProcessManagement Wooledge wiki .