3 ms·
For those that would try to talk themselves out of it and ^C the process, it could be useful to make things a little bit harder by putting the process in the ba
by mattrighetti 3y ago
For those that would try to talk themselves out of it and ^C the process, it could be useful to make things a little bit harder by putting the process in the background :)
There are multiple ways to achieve this:
nohup focus.sh &
nohup stands for "no hang up". It will run a command/script in such a way that it ignores the SIGHUP signal. The SIGHUP signal is typically sent to a process when the terminal is closed or the session is terminated [0].
Another way could be to put the process in the background and then use `disown`, which removes the job from the shell's job table [1], effectively disassociating it from the shell session. This prevents the job from receiving SIGHUP signals just as before.
./focus.sh &
disown
Finally
setsid focus.sh
This will launch the script in a new session [2], so that when you close your terminal it won't receive your current session's SIGHUP signal.
A very good StackOverflow explanation [3].
EDIT: actually, ^C the process already is a bit of a PITA since you would then need to manually put back the original /etc/hosts file :D
- [0]: https://www.man7.org/linux/man-pages/man1/nohup.1.html https://www.man7.org/linux/man-pages/man1/nohup.1.html
- [1]: https://linuxcommand.org/lc3_man_pages/disownh.html https://linuxcommand.org/lc3_man_pages/disownh.html
- [2]: https://www.man7.org/linux/man-pages/man2/setsid.2.html https://www.man7.org/linux/man-pages/man2/setsid.2.html
- [3]: https://unix.stackexchange.com/a/148698 https://unix.stackexchange.com/a/148698