I want to launch an app in a separate X server. It needs a window manager behind it, though.

I created a script

x-window-manager &

and launched it with

xinit myscript.sh -- :1

The problem is: even after closing the app, the window manager keeps running. I want it to quit after my-gui-app exits.

Is it possible to achieve it?


2 Answers 2


Try to add a last line kill %1 In interactive shells at least you can kill the pid of the background job this way. Otherwise look if the process can write a pid file or use killall, if you're sure, there's only one process of this wm


kill -TERM -$$ (kill current process group) should also do it in a race condition-safe manner.

This or kill % should be preferred to killing by pid or by name.

  • Killing the process group might kill parents of the script, depending on how it was started. If you want to use process groups here, use setsid or otherwise ensure that the shell runs in its own process group. Aug 2, 2015 at 18:29

You must log in to answer this question.

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