Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

learn linux and unix commands - unix shell scripting

Single Instance

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-14-2006   -   Original Discussion by sendhil
sendhil's Unix or Linux Image
sendhil sendhil is offline
Registered User
 
Join Date: Feb 2006
Last Activity: 17 February 2006, 12:09 AM EST
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Single Instance

Hi,

I have a script. I want only one instance of the script to be running at any point of the time. How can I do it.
what would be the exact format of the ps command for doing this. For example the name of my script is "Inst.sh"

Thanx in advance
Sponsored Links
    #2  
Old Unix and Linux 02-14-2006   -   Original Discussion by sendhil
vino's Unix or Linux Image
vino vino is offline Forum Advisor  
Supporter (in vino veritas)
 
Join Date: Feb 2005
Last Activity: 8 February 2016, 5:12 PM EST
Location: Sydney, Down Under
Posts: 2,848
Thanks: 0
Thanked 13 Times in 13 Posts
ps listing gives you all the processes that are running. If more than one instance of Inst.sh is running, you plan to kill the other instances ? Better would be to introduce a lock file concept rather than killing processes.

ps x | grep '[I]nst.sh' gives you the pid(s) of Inst.sh

See the lock file getting used in how to detect my script is already running and How to check if another instance of the process is running
Sponsored Links
    #3  
Old Unix and Linux 02-14-2006   -   Original Discussion by sendhil
matrixmadhan's Unix or Linux Image
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
 
Join Date: Mar 2005
Last Activity: 10 January 2017, 8:10 AM EST
Location: classification algos
Posts: 3,215
Thanks: 19
Thanked 31 Times in 28 Posts
why to kill the other instances,
while booting the particular script itself just make a check if any of the previous instance is currently running if so dont boot the new instance.
Sponsored Links
Closed


Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Multiple lines in a single column to be merged as a single line for a record Bhuvaneswari Shell Programming and Scripting 1 08-11-2011 04:16 AM
Replace single quote with two single quotes in perl DushyantG Shell Programming and Scripting 3 04-07-2011 03:16 AM
getopts ... only allow a single instance of an argument? hcclnoodles Shell Programming and Scripting 1 04-09-2009 11:04 AM
replace first instance(not first instance in line) IronHorse7 Shell Programming and Scripting 3 02-07-2008 01:29 PM
Single Instance of a Shell Script pathanjalireddy Shell Programming and Scripting 4 04-19-2005 09:42 AM



All times are GMT -4. The time now is 03:37 PM.