You are not logged in.

#1 2020-04-14 08:46:05

xobcib
Member
Registered: 2020-04-13
Posts: 2

bash/i3 - Disowned child quits when parent quits unless sleep is used

I'm trying to use urxvt as an application launcher where it pops up with a text user interface where I can select which application to launch.
However, after forking, closing urxvt causes the started program also quits.
When trying to see if there were any errors, I used the sleep command to prevent urxvt from closing, but it seems that using sleep after forking fixes the problem. urxvt quits and the started program keeps running.
What's going on here?

line in i3 config to start launcher:

 bindsym $mod+r exec urxvt -geometry 80x6 -name urxvt-launcher -title Launcher -e sh -c "~/bin/launcher.sh" 

environment variables in normal shell http://ix.io/2hXB
environment variables in script http://ix.io/2hXE

minimal non-working script:

#!/bin/bash
nohup xclock &

minimal working script:

#!/bin/bash
nohup xclock &
sleep 1

urxvt version - 9.22
bash version - 5.0.16(1)
i3 version - 4.18

Offline

#2 2020-04-14 14:11:53

Ropid
Member
Registered: 2015-03-09
Posts: 1,069

Re: bash/i3 - Disowned child quits when parent quits unless sleep is used

I don't know why your non-working example is behaving like it does, but I have some ideas you can try as alternatives:

Is starting the program the last thing you want to happen in your script? If you don't need to run any commands after starting the program, then you can use "exec" to stop your script in that spot, like so:

exec nohup xclock

This should close the terminal window because of the "nohup" making the program not connected to the terminal.

Another idea, there's a bash command "disown". Perhaps try using that command instead of nohup, like so:

xclock &> /dev/null &
disown $!

This one seems to behave strange here for me. I tried running the following as a test in a terminal window:

xclock & disown $!

What's strange is: when I run "exit" in this terminal window while xclock is still open, then there's a noticeable delay before the terminal window closes, it doesn't close instantly.

Offline

#3 2020-04-14 15:39:35

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,665

Re: bash/i3 - Disowned child quits when parent quits unless sleep is used

Try

urxvt -hold -e nohup sh -c 'xclock &'

This will fail as well

urxvt -hold -e sh -c 'xclock &'

("-hold" keeps urxvt running, it's not the cause)

Offline

#4 2020-04-15 00:37:12

xobcib
Member
Registered: 2020-04-13
Posts: 2

Re: bash/i3 - Disowned child quits when parent quits unless sleep is used

Using

 exec nohup xclock 

works, but the other suggestions don't.
I've discovered another interesting behavior, the non-working cases work if I launch the script directly from the terminal. I thought there could be a problem with i3 so I used xbindkeys to start the scripts, and everything works as expected. So is this a bug with i3?

Offline

#5 2021-01-02 07:19:09

Buckets
Member
Registered: 2020-12-31
Posts: 2

Re: bash/i3 - Disowned child quits when parent quits unless sleep is used

Working on the same project (an app launcher), I had the same problem. The script would execute then immediately close both the terminal and the application targeted for launch.

Here is my bindsym command:

bindsym $mod+Shift+z exec alacritty -e /bin/bash -c '~/.scripts/apps/apps.sh'

With regards to launching apps, this worked fine from terminal but not through i3 bindsym:

firefox & disown

I could append && $SHELL to my bash command in the bindsym to keep everything open. Problem was for my program, I wanted the terminal to close and for the targeted application to launch by itself.

Your solution didn't work for me, but I added & and it worked.

exec nohup firefox &

I can't in good conscience leave my comment at that because that alone actually doesn't work for me. The part of my app launcher script in question looks as follows, and if I remove the 'clear' command from the bottom, it breaks and the terminal + app shutdown immediately again.

echo "Choose an app"
echo

options=("alacritty" "arandr" "firefox" "flameshot" "gimp" "gpick" "nvidia-settings" "pavucontrol" "spotify" "typora")

select_option "${options[@]}"
choice=$?
app=${options[$choice]}

case $app in
    alacritty)
        exec nohup alacrity &
        ;;
    arandr)
        exec nohup arandr &
        ;;
    firefox)
        exec nohup firefox &
        ;;
    flameshot)
        exec nohup flameshot &
        ;;
    gimp)
        exec nohup gimp &
        ;;
    gpick)
        exec nohup gpick &
        ;;
nvidia-settings)
        exec nohup nvidia-settings &
        ;;
    pavucontrol)
        exec nohup pavucontrol &
        ;;
    spotify)
        exec nohup spotify &
        ;;
    typora)
        exec nohup typora &
        ;;
esac
clear

The strangest bug I've ever seen in all my years and probably seems tangential but I have to include it because my solution is incomplete without it (somehow).

Offline

#6 2021-01-02 07:30:43

VoDo
Member
From: Europe
Registered: 2020-06-04
Posts: 122

Re: bash/i3 - Disowned child quits when parent quits unless sleep is used

look at dmenu it is triggered by mod+d I use it as a launcher.


Archi3

Offline

Board footer

Powered by FluxBB