Thanks for your response, Glynn. <br>Now I see that the GIS_LOCK variable is not the name of the lock file created - it is a &quot;parameter&quot; for $GISBASE/etc/lock. <br>As I understand it, when GRASS is started normally, i.e. using grass63 -text &lt;gisdbase&gt;/&lt;location&gt;/&lt;mapset&gt;, the Init.sh file is run and all the environmental variables are set, inlcuding checking/creation of .gislock file. <br>
When I use a grass module inside a script, Init.sh is not executed so all necessary env. variables need to be set either inside the script itself, or in system .bashrc file. <br>I&#39;ve set the GIS_LOCK back to $$ (i.e., PID number). What happens is this: when I run a script containing GRASS modules, no Init.sh process is initiated so $GISBASE/etc/lock is not executed. Does it mean that I need to execute the $GISBASE/etc/lock explicitly inside my script? <br>
<br>Jana<br><br><br><div class="gmail_quote">On Wed, Aug 10, 2011 at 12:35 AM, Glynn Clements <span dir="ltr">&lt;<a href="mailto:glynn@gclements.plus.com">glynn@gclements.plus.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im"><br>
Jana Krajcovicova wrote:<br>
<br>
&gt; I would like to call GRASS modules from other programs - e.g. shell or perl.<br>
&gt; The information I found on grass wiki was a bit confusing for me,<br>
&gt; nevertheless I decided to test this possibility.<br>
&gt; I added GRASS environmental variables to my .bashrc file:<br>
&gt;<br>
&gt; # path to GRASS binaries and libraries:<br>
&gt; export GISBASE=/usr/lib64/grass-6.3.0<br>
&gt; export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts<br>
&gt; export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GISBASE/lib<br>
&gt; export GISRC=/home/mirka/grass/gisrc<br>
&gt; export GIS_LOCK=.gislock<br>
&gt;<br>
&gt; Now, when I wrote a script, I create the gisrc file on the fly inside the<br>
&gt; script, specifying the location and mapset.<br>
&gt; Then I call a GRASS module, e.g., r.report, directly and it works fine.<br>
&gt; However, what bothers me, is the gislock, as it doesn&#39;t work properly -<br>
&gt; i.e., when I run the script outside GRASS it performs an operation on the<br>
&gt; specified location/mapset combination even in case the same combination of<br>
&gt; location/mapset is explicitly opened in another terminal.  I guess something<br>
&gt; is wrong with my specification of GIS_LOCK env. variable ...<br>
<br>
</div>GIS_LOCK should be a PID, not a filename. Specifically, it should be<br>
the PID of a process which will exist for the lifetime of the session.<br>
You should use $GISBASE/etc/lock to create the .gislock file.<br>
<div class="im"><br>
&gt; I am not sure how this is supposed to operate, but what I observe is that<br>
&gt; the env. variables which I specify in .bashrc file, namely GISRC are only<br>
&gt; used for the modules called from scripts outside GRASS. When I open a<br>
&gt; location/mapset combination directly using grass, it creates gisrc file in<br>
&gt; /tmp/grass6-username-processID directory.<br>
<br>
</div>The startup script creates a new $GISRC file for each &quot;session&quot;; this<br>
allows you to have multiple concurrent sessions. It copies ~/.grassrc6<br>
to /tmp/grass6-&lt;user&gt;-&lt;pid&gt;/gisrc then sets GISRC to refer to that<br>
file.<br>
<div class="im"><br>
&gt; As for the .gislock, I thought it should always be  located in the<br>
&gt; corresponding gisdbase/location/mapset directory. Then, why my scripts<br>
&gt; ingnore .gislock created by explicitly opened GRASS location/mapset?<br>
<br>
</div>Because your script isn&#39;t checking for a lock file. $GISBASE/etc/lock<br>
checks for the existence of a lock file, and creates one if it doesn&#39;t<br>
exist. It returns an exit code of 2 if a lock file already exists (and<br>
the owner process is still running) and 0 if it created one<br>
successfully (an exit code of 1 indicates some other error).<br>
<br>
Also, if the PID stored in the lock file doesn&#39;t refer to an existing<br>
process, the lock file is considered stale (the behaviour is as if no<br>
lock file exists).<br>
<br>
Look at $GIBASE/etc/Init.sh for more information on what is involved<br>
in creating GRASS sessions.<br>
<font color="#888888"><br>
--<br>
Glynn Clements &lt;<a href="mailto:glynn@gclements.plus.com">glynn@gclements.plus.com</a>&gt;<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>******************************************<br>Jana Krajčovičová, PhD.<br>Department of Air Quality<br>Slovak Hydrometeorological Institute<br>Jeséniova 17<br>831 01 Bratislava<br>
<br><a href="mailto:jana.krajcovicova@shmu.sk">jana.krajcovicova@shmu.sk</a><br><br><br>