Sponsored Content
Top Forums Shell Programming and Scripting checking for a running process from korn cron Post 70544 by blowtorch on Sunday 1st of May 2005 12:27:20 AM
Old 05-01-2005
Best way to implement this is to use a lock file. When the process starts up, have it look for a lock file (which should be a unique file name). If the file exists, the process can just exit. Otherwise, the process can touch the file and proceed to do its job. Just before exiting the process will remove the file.

Code:
#!/bin/sh
LOCKFILE=/tmp/lockfile # just suppose some name
if [ -f $LOCKFILE ]; then
exit
fi
touch $LOCKFILE  # create your lockfile so that any process starting up after 
                        # will find the file and exit
### start doing what you really want to do here
.
.
.
### end what ever you are doing here
rm -f $LOCKFILE
exit

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Korn Shell script not running

I am sorry, this is really trivial, yet I am not able to understand what the problem is! I am using korn shell and running this script #!/bin/ksh keep=3 while ; do echo $keep keep=$(($keep-1)) done I am getting this error: `keep=$' unexpected I am not able to understand it because ... (1 Reply)
Discussion started by: Asty
1 Replies

2. Shell Programming and Scripting

Shell running setup in Korn ?

I am starting to code a few ideas of customization and tasks improvements on the office UNIX machine. My first script (see below) only contains ALIAS commands. But for some reason, when I execute it, the alias are not executed. I suspect it is because of the "#!/bin/ksh" not being recognized or... (4 Replies)
Discussion started by: Browser_ice
4 Replies

3. UNIX for Dummies Questions & Answers

perl scripting for checking if a process is running

Hi All, I am new to perl and have been trying to write a short script to check a process.Though i havent reached to the stage where i can match the output. I am trying to pass a variable x with value /opt/RGw/csbp-base/CSBP_BAT.01.00.05/csbp_BAT.01.00.05.jar and then pass another variable... (2 Replies)
Discussion started by: pistachio
2 Replies

4. Shell Programming and Scripting

Checking the cron process in unix

Hi Experts, Is there any command by which i can chk that the cron process is running fine? Say i have scheduled the cron to run at 10 o clock every monday,Do i need to wait for the time it runs and then chk using ps -ef? Please shed some light. Thanks Ashok. (2 Replies)
Discussion started by: Ashok_oct22
2 Replies

5. UNIX for Dummies Questions & Answers

running script with korn shell

How would i instruct the current shell to run the current script using the korn shell? (1 Reply)
Discussion started by: JamieMurry
1 Replies

6. UNIX for Dummies Questions & Answers

Checking Unix Performance - Why is a process running slowly?

Hi Please can someone explain to me how they would go about monitoring the performance of a process in Unix. Lets say that a user is running a process in Unix but it seems to be taking a long time, whereas it completed a lot quicker yesterday. How would you go about investigating what is causing... (1 Reply)
Discussion started by: Sunny Sid
1 Replies

7. Shell Programming and Scripting

Running Shell Script in the cron, background process

Hi, i was looking for an answer for some trouble im having runing a script in the cron, thing is, that when i run it manually it works just fine. But when cron runs it, it just doenst work. I saw a reply on a similar subject, suggesting that the . .profile worked for you, but im kind of... (9 Replies)
Discussion started by: blacksteel1988
9 Replies

8. Solaris

Cron job running even after cron is removed

Hi , I have removed a cron for particular user , but cron job seems to be running even after the cron entry is removed. The purpose of the cron was to sendmail to user ( it uses mailx utility ) I have restarted cron and sendmail service still user is getting mail alerts from the cron job. And... (4 Replies)
Discussion started by: chidori
4 Replies

9. Shell Programming and Scripting

Issue Running UNIX process from CRON !!

Experts, Not sure whether the problem described here is related with Unix or is it with Oracle Installation. Here is the description of the issue: A new Unix server is setup as a part of Unix and Oracle upgradation activity for one of the Application, I work on. One strange thing is... (2 Replies)
Discussion started by: Oracle_User
2 Replies

10. Shell Programming and Scripting

Checking running process status using "grep" on multiple servers in load sharing system.

Suppose i have 3 different servers say x,y and z. Im running some process say ABC and 40 instances for the same is being created. In load sharing suppose on server x, 20 instances are running server y, 10 instances are running server z, 10 instances are running. While checking the... (1 Reply)
Discussion started by: ankitknit
1 Replies
RLOCK(1)						      General Commands Manual							  RLOCK(1)

NAME
rlock - run program with a lockfile SYNOPSIS
rlock [options] lockfile program [args] rlock [options] lockfile -- program options [args] DESCRIPTION
rlock creates NFS safe lockfiles. it can optionally run a program while holding the lock, ensuring lockfile removal on program exit. if a program is specified to be run rlock will spawn a background thread to kept the lockfile 'fresh' by touching it at a regular interval. in this way a lease is maintained on the lockfile and other processes attempting to obtain the lock can determine that it is in use. see the '--refresh' option for how to control the touch interval. any other process trying to obtain a lock will automatically remove a stale lockfile; a stale lockfile is one that is older than a certain age. this age be controled via the '--max_age' option. ENVIRONMENT
LOCKFILE_DEBUG=1 causes internal actions of the library to be shown on STDERR. DIAGNOSTICS
rlock attempts to exit with the status of 'program' except where it cannot due to exceptional conditions. in addition the message 'RLOCK SUBCOMMAND FAILURE' will be printed on STDERR if 'program' exits with non-zero status. AUTHOR
lockfile was written by Ara T. Howard <ara.t.howard@noaa.gov>. This manual page was converted by Decklin Foster <decklin@red-bean.com> for the Debian project (but may be used by others). 2008-10-11 RLOCK(1)
All times are GMT -4. The time now is 11:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy