How to kill the process when the file is locked?

I was trying to read the file to create a table in SAS and I got error as follows while I read.

 
Resource is write-locked by another user.  File 
=/usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer_2015-09-29_tmp_18208.log.  System Error Code = 
0.
ERROR: File is in use, /usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs/SASApp_STPServer__2015-09-29_tmp_18208.log

I've closed this file before I read the file and I'm not sure why I'm getting this error.

How to overcome this error? How to check which process is responsible for the lock?

The message is quite clear, someone else is using the file...
To overcome contention issues SAS offers a module ( for $$$) called SAS SHARE...

You could write a bit of SAS code to when it sees a locked file to continue the process in readonly mode...

1 Like

May I request you to get me the code to overcome this error?

Do you have SAS-SHARE?

Yes, I've.

OK but You will have to wait I get to work...

1 Like

Thanks for your patience and support.

I can wait for your reply.

This is for a SAS 9.4 :
HOME=/opt/sas/9.4/SASFoundation/9.4/

You should have config files for share, if you dont
Go to $HOME/utilities/bin
If you dont have a directory called files create it with owner and group the appropriate SAS user
Create the followings files you need to modify according to what you want as shared libraries

create a .sas file e.g. start_share.sas
with in:

%let servername=sashrsrv;
options comamid=tcp;
libname geco '/data/mnt2/geco' ;
libname stil '/data/mnt1/stil' ;
libname fire '/data/mnt3/fire' ;
proc server id=&servername authenticate=optional;
run;

and a stop_share.sas file:

%let servername=sashrsrv;
options comamid=tcp;
proc operate server=&servername;
stop server;
quit;

Now you need to write a script to call those 2 files to start and stop SHARE:
e.g. here is for the start

HOME=/opt/sas/9.4/SASFoundation/9.4/utilities/bin/files
SASROOT=/opt/sas/9.4/SASFoundation/9.4
ConfigFile1=$HOME/start_share.sas
ConfigFile2=$HOME/stop_share.sas
LOGFILE1=/var/opt/sas/share/start_s94s.log
LOGFILE2=/var/opt/sas/share/stop_s94s.log

nohup $SASROOT/sas -sysin $ConfigFile1 -noterminal -logparm "write=immediate"\
       -log $LOGFILE1" >/var/opt/sas/log/rc.sas94share.log 2>&1
...

the stop command would be:

nohup $SASROOT/sas -sysin $ConfigFile2 -noterminal -unbuflog -log $LOGFILE2" \
        >>/var/opt/sas/log/rc.sas94share.log 2>&1

I let you adapt to your needs...
write a nice start/stop script you can put in the servers booting process ...

1 Like

Could you please guide me for SAS 9.3?

In your reply, when should I run the start and stop script?

for 9.3 its exactly the same... It depends how your SAS software was installed.. all SAS env has a SASROOT somewhere...
On what OS are you running?
Start/stop script are for boot time usually so you have to think of who is to run the process since that user can/will have to stop restart modify the configuration etc... so it should not be root and for the system boot you will need to do an su to that user:

(su $SASSHAREUSER -c "nohup $Program -sysin $ConfigFile1 -noterminal -logparm "write=immediate"\
       -log $LOGFILE1" >/var/opt/sas/log/rc.sas94share.log 2>&1 &)

We stop/start every evening:
Stop - and we stop SAS metadata servers too in order to cleanup all temporary storage ( using SAS cleanwork utility...) then restart all the other reason is SAS share logs grow enormously if you have a lot of activity, its a easy means to reset... and keep daily logs...

I forgot to mention SAS will read /etc/services to look for the sasshare name you gave in the config file as above

%let servername=sashrsrv;

the to get the TCP port number
So in /etc/services you need a line:

sashrsrv        5520/tcp           # sas/share server

Choose a free port accordingly to your system... ( to modify /etc/services you normally must be root...