Context
I have a Makefile that exposes a test command. The test command runs a server and a separate integration process that runs a suite against the server. I would like to programmatically kill the application when the tests finish.
Makefile
test:
export APP_ENV=test
go run main.go &
npm run ci
# tried the following:
# kill -9 $(lsof -t -i:3000)
# ps -ef | grep "go run main.go" | tr -s ' ' | cut -d ' ' -f2 | xargs kill
# kill -9 "$!"
They each receive an empty process id instead of the correct one. Any advice?