What will be the effect of environment variable, when mulitple sessions are opened by same login?

Hello,

What will be the effect of environment variable, when mulitple sessions are opened by same login?

Following code snippet is part of a shell script.

Environment : HP-UX B.11.31 U ia64

For Example

 EXECUTION_DIR=`pwd`/
EXECUTION_DIR_RT=${EXECUTION_DIR}RT/
export EXECUTION_DIR_RT
 

Question:
If there multiple sessions opened on the same host by the same user login , to execute shell script in parallel, what will be the effect?

Ultimatly need to ensure that each session uses it's own execution directory.

However I am getting the execution directory are messed up, due to multiple session opened by the same user login and script are executed concurrently.

Thanks for your answers, views and suggestion in advance.

Each session will keep it's own version of the environmental variable and it's value. There could be contention if you are writing files of the same name to the same directory I suppose, but processes of one session cannot generally be affected by those in another, even if it is the same user account.

If you need to ensure they work with separate directories, you could do this:-

my_dir=$(mktemp -d)

This will create a unique directory in /tmp. You can change that if you like to create a unique directory under a path you specify, especially if your files are large or the data is sensitive:-

my_dir=$(mktemp -d /path/to/base/dir)

I hope that this helps,
Robin

One solution is to create an execution directory dynamically for each login.

pid=$$
EXECUTION_DIR=`pwd`/${pid}/  # < directory with current process pid
[ ! -d ${EXECUTION_DIR} ] && mkdir ${EXECUTION_DIR}

This tests to see if the directory exists, and if it does not exist create one.

[edit] oops rbatte1 types fast!.

1 Like

Thanks jim mcnamara rbatte1.

After creating the directory based on the Process ID ( pid=$$ ), if I want to move the output files from the respective Process ID folder to some other directory, how can I make it.

 For Process 1:
 Like IF { Process_ID == $$ ) mv ${EXECUTION_DIR}\*  \Ouptut1\
  
 For Process 2:
 Like IF { Process_ID == $$ ) mv ${EXECUTION_DIR}\*  \Ouptut2\
 

Thanks, Siva SQL

As the process ID doesn't change during a session, you don't need the if construct. And, you need a mechanism to assign the output directory number. Something like counting up a counter, or determine the last directory's number and increment that.