The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
running exe phani_sree High Level Programming 2 11-23-2006 06:54 AM
Running .sh from PHP??? royh Shell Programming and Scripting 1 07-03-2005 04:32 AM
Running cgi CSGUY UNIX for Dummies Questions & Answers 3 04-30-2005 08:42 PM
running .sh, .sql .etc how to? etravels UNIX for Dummies Questions & Answers 2 02-12-2004 09:31 AM
running NIS over ssh Andy Hibbins Security 2 10-12-2001 08:22 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-14-2006
tikang tikang is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 2
How to prevent job1 from running while job2 is running..

Hi,

Please I need your expert advise on how to prevent/lock from execution job1 while job2 is still running in Unix... THanks
  #2 (permalink)  
Old 09-14-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Use lockfiles. Before any job starts, make sure it checks for a lockfile. If the file exists, exit. If it does not, have it create the lockfile and proceed to do its actual job. At the end, remove the lockfile.

If you have two jobs and one lockfile, you'll get only one job running at any given time.
  #3 (permalink)  
Old 09-14-2006
tikang tikang is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 2
Hi, kindly give an example script of lockfiles usage?
  #4 (permalink)  
Old 09-14-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
Code:
# cat one.sh
#!/bin/ksh

if [ -f /tmp/lockfile ]; then
        exit
fi
touch /tmp/lockfile
echo "Process one doing work..."
sleep 10
echo "Process one completed work..."
rm /tmp/lockfile
# cat two.sh
#!/bin/ksh

if [ -f /tmp/lockfile ]; then
        exit
fi
touch /tmp/lockfile
echo "Process two doing work..."
sleep 10
echo "Process two completed work..."
rm /tmp/lockfile
# ./one.sh &
[1] 7377
# Process one doing work...

# ./two.sh
# ./two.sh
Process one completed work...
# ./two.sh
Process two doing work...
Process two completed work...
#
As you can see, process two, didn't start as long as process one was running.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:04 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0