[Tfug] Properly terminating a shell script after using X Windows esadyna3

Bexley Hall bexley401 at yahoo.com
Sat Jan 26 11:54:50 MST 2013


Hi John,

On 1/25/2013 2:55 PM, John Gruenenfelder wrote:

> I was hoping for something a little more general/generic.  For

> So... I guess what I'm getting at is that I, personally, could use any
> number of methods to make sure the script exits on *my* computer.  I
> would like to make this useful for other people, however, and the
> fewer changes they are required to make to their X startup procedure,
> the better.  That is why I am hoping to find, if possible, some fairly
> general method of exiting the script when the user logs out so that it

-----------------------------------------------------^^^^^^^

"Logs out" or "quits his X session"?

> "just works" in most cases.
>
> I suppose, failing that, I could put together an instructions file
> that includes a list of numerous methods of both starting and stopping
> the script and then let the user chose the methods that best match how
> their system is configured.  That's still far more manual a process
> than I was hoping for, however.

You either have to tell "something" (see my previous post)
that you are running (and have that "something" kill you
when X dies) *or* you have to sense when that "something"
(X) dies and kill yourself!

If you want to be independent of the means by which X(1) is started,
then you have to wrap X(1) in a script/executable and rename it
so that the rest of the system thinks that this "enhanced X" is the
real X server.

[On many systems, X is a {sym,hard}link to the real Xserver(1)
so, as long as everyone accesses "X" using that handle, you're
golden -- just replace the symlink with a real script that
references the real Xserver (or, any variant of this scheme)]

The enhanced X can deliberately kill off "whatever" -- perhaps
anything that is a descendant of it's own process!  (this might
be bad if you wanted to start something in X and have it
persist beyond the scope of your X session!  I.e., exactly what you
are trying to *avoid*!)

The other way (less draconian) is for you to record your PPID
on startup (and details associated with it so that you can
uniquely identify it, later!).  Then, periodically (i.e.,
whenever you think it prudent to die), check to see if that
process is still running (i.e., $PPID must still be active
owned by same user, same executable, controlling pty, etc.)

I suspect somewhere there is a little scriptlet that already
does all of this -- to varying degrees of pedantic-ness.
HTH,
--don




More information about the tfug mailing list