[GRASS-dev] BASH question about quitting GIS Manager

Repeatedly there have been requests to make it possible to quit GRASS when quitting the GIS Manager (and to automatically quit the GIS Manager when quitting GRASS).

I had an idea that I thought I run by everyone and see if I could get some suggestions about getting it to work.

  1. When the GIS Manager shell script is first run (gis.m& to run in background), have it set an environmental variable. For example…
    export GRASS_GUI_RUN=”TRUE”

  2. The script would idle away, waiting for any change to the environmental variable (this is a part I’m not sure how to do)…
    while GRASS_GUI_RUN==”TRUE”
    … let the GIS Manager run

  3. When the GIS Manager quits (or quits with an option to exit GRASS), it could set this variable to false
    set env(GRASS_GUI_RUN) “FALSE”

  4. The script would exit its while loop and echo “exit” to the GRASS command prompt, “shutting down” GRASS (i.e., resetting the GRASS environment and closing the GRASS shell).

Would something like this work???

If so, we also might be able to use this for automatically quitting the GIS Manager.
-Write into the GRASS exit routine a check for the GRASS_GUI_RUN environmental variable
-If it is set to TRUE, kill WISH.

What do you think?

Michael


Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics and Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

Michael Barton wrote:

Repeatedly there have been requests to make it possible to quit GRASS
when quitting the GIS Manager (and to automatically quit the GIS
Manager when quitting GRASS).

..

-Write into the GRASS exit routine a check for the GRASS_GUI_RUN
environmental variable
-If it is set to TRUE, kill WISH.

What do you think?

`killall wish`, but that would take out any other tcltk programs the
user is running. (incl other mapsets sessions..)

maybe better

GRASS_GUI_RUN=$$ (you need to get the PID of gis.m from the parent,
not sure how to do that)

then `kill $GRASS_GUI_RUN`

FWIW I like to start grass in text mode, start gis.m from the command
line, quit gis.m but stay in my grass session. So quiting gis.m
shouldn't force a quit of the entire grass session in all cases..

also be careful to shut down the command line cleanly so .tmp/ gets
cleaned, etc.

Hamish

ps - isn't the "&" in gis.m& redundant now?

From: Hamish <hamish_nospam@yahoo.com>
Date: Thu, 9 Nov 2006 17:24:07 +1300
To: Michael Barton <michael.barton@asu.edu>
Cc: <grass-dev@grass.itc.it>
Subject: Re: [GRASS-dev] BASH question about quitting GIS Manager

Michael Barton wrote:

Repeatedly there have been requests to make it possible to quit GRASS
when quitting the GIS Manager (and to automatically quit the GIS
Manager when quitting GRASS).

..

-Write into the GRASS exit routine a check for the GRASS_GUI_RUN
environmental variable
-If it is set to TRUE, kill WISH.

What do you think?

`killall wish`, but that would take out any other tcltk programs the
user is running. (incl other mapsets sessions..)

maybe better

GRASS_GUI_RUN=$$ (you need to get the PID of gis.m from the parent,
not sure how to do that)

There is a TclTk pid command that will return this value. It is now used to
track PPM maps rendered and displayed in the GIS Manager.

then `kill $GRASS_GUI_RUN`

Worth a try.

FWIW I like to start grass in text mode, start gis.m from the command
line, quit gis.m but stay in my grass session. So quiting gis.m
shouldn't force a quit of the entire grass session in all cases..

Definitely. There should be a "Quit GIS Manager" and a "Quit GRASS" option.

also be careful to shut down the command line cleanly so .tmp/ gets
cleaned, etc.

Doesn't simply typing "exit" at the GRASS prompt do that?

Hamish

ps - isn't the "&" in gis.m& redundant now?

Not if you want to run anything from the GRASS prompt while the GIS Manager
is running.

Any idea how to do the loop I was thinking about?

__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

Michael Barton wrote:

> also be careful to shut down the command line cleanly so .tmp/ gets
> cleaned, etc.

Doesn't simply typing "exit" at the GRASS prompt do that?

yes. also init.sh traps 2 3 15 (INT QUIT TERM). "kill $PID" defaults to
the TERM signal, so killing the grass Init.sh grass session should be
safe IF you know it's PID.

maybe set "export GRASS_PID=$$" in init.sh which the gui could kill?

> ps - isn't the "&" in gis.m& redundant now?

Not if you want to run anything from the GRASS prompt while the GIS
Manager is running.

I've just tried it, it works.
the "&" is in the gui/tcltk/gis.m/gis.m shell script.

Any idea how to do the loop I was thinking about?

my brain sugar is currently way too low to put too give it the thought
it deserves, but is there a way to get the PID of a child from the
parent when you launch it?

something like: (totally non-functional examples)

GRASS_GUI_PID=`exec gis.m`

or

gis.m &
GRASS_GUI_PID=$[?] # but obviously not "$?" or "$$" ... ?

that might make shutting down gis.m when the main grass session exits
easier (add "kill $GRASS_GUI_PID" to init.sh's closedown code).

Hamish

Michael Barton wrote:

Repeatedly there have been requests to make it possible to quit GRASS when
quitting the GIS Manager (and to automatically quit the GIS Manager when
quitting GRASS).

I had an idea that I thought I run by everyone and see if I could get some
suggestions about getting it to work.

1. When the GIS Manager shell script is first run (gis.m& to run in
background), have it set an environmental variable. For example...
export GRASS_GUI_RUN=²TRUE²

2. The script would idle away, waiting for any change to the environmental
variable (this is a part I¹m not sure how to do)...
while GRASS_GUI_RUN==²TRUE²
... let the GIS Manager run

3. When the GIS Manager quits (or quits with an option to exit GRASS), it
could set this variable to false
set env(GRASS_GUI_RUN) ³FALSE²

4. The script would exit its while loop and echo ³exit² to the GRASS command
prompt, ³shutting down² GRASS (i.e., resetting the GRASS environment and
closing the GRASS shell).

Would something like this work???

If so, we also might be able to use this for automatically quitting the GIS
Manager.
-Write into the GRASS exit routine a check for the GRASS_GUI_RUN
environmental variable
-If it is set to TRUE, kill WISH.

What do you think?

If you want a GUI-only mode, the cleanest solution is to implement it
in Init.sh, i.e. run gis.m *instead of* the shell, rather than running
both.

If you want both, but with the shell terminated by gis.m, the cleanest
solution is for Init.sh to start gis.m instead of the shell, and for
gis.m to spawn a new xterm as a child process. gis.m will get the PID
of the xterm, which it can use to kill it when you exit.

You can't easily spawn a child shell on the existing terminal, as you
would need to do some relatively involved process management, beyond
what can readily be done in Tcl.

[E.g. putting the shell into a separate process group to wish, making
the shell the foreground process group and wish the background process
group. You might also need to undo any changes which wish made to the
terminal settings.]

--
Glynn Clements <glynn@gclements.plus.com>