1

TL;DR at the bottom.

I am trying to make a simple lock screen for my laptop running Arch / BSPWM. I found a program called cmatrix which has a screensaver flag that causes it to exit when a key is pressed. I am trying to chain together bspc commands with cmatrix and vlock to make a line that can be run to start cmatrix fullscreen, run vlock when keys are pressed, then exit after vlock exits.

My only problem with this is that in order for the lock screen to be effective, I need to quit sxhkd to prevent people from simply closing the window containing cmatrix/vlock. I have added pkill sxhkd to the chain of commands and that works. The broken part is starting sxhkd back up again. Simply tacking sxhkd on to the end doesn't work as the terminal window won't close until sxhkd finishes, which is never. In addition, if the terminal window is closed, sxhkd stops because it was running in it.

I tried using "sxhkd &", but for some reason this causes the whole thing not to run.

Here is the almost working command I have so far:

urxvtc -e bash -c "sleep 0.1; pkill sxhkd; sleep 0.1; bspc window -t fullscreen=on; sleep 0.1; cmatrix -u 9 -s; sleep 0.1; vlock; sleep 0.1; sxhkd"

The sleep commands are so that the programs don't come up in the wrong order (sometimes the vlock password prompt comes up before cmatrix gets to run)

What it currently does is start a new urxvt window (important if I want my terminal font for cmatrix) and it kills sxhkd to prevent anyone from closing the window. It fullscreens it using bspc and runs cmatrix. When a key is pressed, cmatrix exits and the vlock password prompts comes up. When the password is entered correctly, it tries to restart sxhkd, but they remain coupled.

Any help would be greatly appreciated!

TL;DR

How can I, with a command (usually run from a script), open a terminal window that runs other commands, then starts an application (like a gui app), then the terminal window closes but the gui app keeps running?

Simpler command examples:

urxvtc -e bash -c "echo hello!; sleep 3; pavucontrol" This should print hello!, wait 3 seconds, then launch pavucontrol and close the terminal leaving pavucontrol. Instead, the terminal stays open because pavucontrol is running.

urxvtc -e bash -c "echo hello!; sleep 3; pavucontrol &" This should print hello!, wait 3 seconds, then launch pavucontrol and close the terminal leaving pavucontrol. When the terminal closes after 3 seconds, however, pavucontrol is nowhere to be seen.

2 Answers 2

1

I seem to have stumbled across the solution when playing with nohup by itself. It seems that nohup doesn't completely release the job from the terminal, so running nohup program & exit doesn't work - the terminal complains that there are running jobs. The easy solution is to add another sleep in between them like so:

nohup command & sleep 2 && exit

The sleep can probably be shortened a bit, but if it's too short it will probably cause the nohupped program to close.

Edit: I'm having some inconsistent behavior with nohup and exit though - sometimes it will exit and leave the program running and sometimes it will complain that there are jobs. I'm not certain why it happens.

0

To start and orphan a background process you use nohup my_command &. After that you can exit the starting shell without killing the new process. More on process management.

3
  • Using the simpler test commands, I tried adding nohup pavucontrol & to the end, resulting in urxvtc -e bash -c "echo hello!; sleep 3; nohup pavucontrol &;". Unfortunately, this makes the entire command fail to do anything. It seems to quickly open the terminal window which closes immediately without even running sleep 3. Jan 11, 2015 at 19:50
  • You can't use both & and ; to terminate a command.
    – l0b0
    Jan 11, 2015 at 19:52
  • My bad. It seems to run the echo and sleep, but pavucontrol is nowhere to be seen. urxvtc -e bash -c "echo hello!; sleep 3; nohup pavucontrol &" Jan 11, 2015 at 19:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .