0

guys. I am new to bash scripting and deploying Go on ubuntu. I run my Go program like this

go build -o myprogram main.go
./myprogram &

But now, instead of uploading files with sftp and manually change everything I wanted to write simple bash script.

The problem is that I firstly need to kill existing process and I don't know how to get PID and kill it.

Maybe I can run my program using something different so I don't have to find PID.

I tried using ps ax | grep myprogram and then kill it, but no luck

Rustam Ibragimov
  • 2,571
  • 7
  • 22
  • 33

1 Answers1

1

bash has a special variable $! that you can use to store the process id of the most recently started background process

./myprogram &
myprogram_PID=$!

kill "$myprogram_PID"
Inian
  • 80,270
  • 14
  • 142
  • 161