4

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

I created a script

#!/bin/sh
x-window-manager &
my-gui-app

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?

5

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

1

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. – Gilles Aug 2 '15 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.