I have a bash script which is executed via the GUI (lightdm).In some line during the script, I want it to:sudo service lightdm stop - stop the GUITake over a TTY (like tty1 or tty7) using e.g.: exec </dev/tty7 >/dev/tty7 2>&1(if agetty controls the TTY, we can easily send it SIGSTOP).tty7 is preferred since that while shutting down lightdm, it will be available.The problem is that the bash script is a child of the lightdm service.Therefore while executing sudo service lightdm stop - it will try to terminate my script/process.I found out that I need to use nohup but I prefer to have my already running script/process immune to SIGHUP.I've seen suggestions about disown and bg but a script file isn't in interactive mode therefore I can't bg it. Also using set -m won't help because that anyway I need to press CTRL+Z in order to suspend my process (Sending SIGTSTP will suspend it but the file won't continue to run...).What is the reliable & robust approach to solve this?Using Ubuntu.Update 8 Oct 21:35 UTC - Replying to @countermode:I tried:trap '' HUPservice lightdm stopalso tried:trap '' SIGHUPservice lightdm stopBut it failed.I know that it failed because that after the line service lightdm stop I write to files some data. Those files modification time is too old (a day ago), thus it doesn't work.I tried to catch all the signals that I thought I was missing, using:trap_with_arg() {    func=$1 ; shift    for sig ; do        trap trap_handler $sig $sig    done}trap_handler() {    echo -e  \n Caught signal $1 \n >>/path_to_some_folder/_signals.txt}echo  >/path_to_some_folder/_signals.txtsignals_list=for i in {1..64} ; do    signals_list+=$(kill -l $i) donetrap_with_arg trap_handler 0 $signals_listservice lightdm stopAs advised here.All the signals which were caught are (left was first): HUP, CONT, 0.So I tried to:trap '' 0 HUP CONTservice lightdm stopBut it failed as well...Update 9 Oct 08:46 UTC:Actually the answer of @countermode works well.I had a tiny mistake in the code so I thought it doesn't work.
Child process continues to run if parent dies
tty;signals;disown
Shell scripts can set their own signal handlers using the trap keyword. In your scenario you want to ignore SIGHUP, so you would call somewhere before terminating the ldm sessiontrap '' SIGHUPwhere '' (the empty string) indicates that you want to ignore SIGHUP (you would otherwise specify the signal handling code here).