5

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?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
marmistrz
  • 2,732
  • 4
  • 23
  • 30

2 Answers2

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

allo
  • 916
  • 1
  • 7
  • 13
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.

Petr Skocik
  • 28,176
  • 14
  • 81
  • 141
  • 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 'SO- stop being evil' Aug 02 '15 at 18:29