I start a process using foo &.It outputs something like:[1] 16915This is the process id, I guess.How can I store this number into a variable named MY_PROCESS_ID (for example)?Then I can do:kill $MY_PROCESS_IDand my process id will be killed.
How to kill a process started as daemon?
linux;bash;shell script;process
foo &bg_pid=$!kill $bg_pidYou can also use the shell's internal kill command with (at least in case of bash) the job number:foo &kill %1But that's probably not easier. May be easier interactively. But withkill %+orkill %you always get the last one. You can even identify the job to be killed by parts of the command line. See man bash; search for the block JOB CONTROL.