No lock file: Preventing multiple instance of a script
I've been bitten by using a lock or pid file to prevent multiple instances of a script. A user typed kill -9, and the pid file didn't go away. You can't trap -9. So when he tried to restart, it said "already running", and I got trouble report. Argh.
So here's what we came up with:
It does use a temp file, but leaves no potential artifact to mess us up later.
If you try this without a temp file, you'll end up with a false positive because pids=$(ps | grep $0 | grep -v grep | cut -d ' ' -f 1) seems to leave it's own extra pid.
Last edited by Scott; 11-17-2011 at 09:43 PM..
Reason: Please use code tags
;)Hi Everyone,
I am using solaris 5.10.
I have a java process running in server mode in unix.
The problem is that it automatically forks i.e creates a child process.
I mean suddenly two instances of that process start running , in which the process-id of first instance is the parent... (0 Replies)
Hi Everyone,
I am using solaris 5.10.
I have a java process running in server mode in unix.
The problem is that it automatically forks i.e creates a child process.
I mean suddenly two instances of that process start running , in which the process-id of first instance is the parent... (5 Replies)
I am trying to debug the following script. It appears that when the check for script running occurs, it's finding the actual grep statement and causing the script believe the script is already running. This is deployed on two different servers where one works fine, the other doesn't. Any ideas?
... (2 Replies)
Hi All,
I have a problem mentioned below.
I have a script which performs line by line operations on several files.
I have a temp_file storing the list of names of the file to be validated. Right not in while loop i validate these files one by one.
Is there anyway that i can modify... (1 Reply)
Hi all,I have some questions of forking new process,the code is below.Any help will be appreciated.
1 #! /bin/bash
2
3 PIDS=$(pidof sh $0)
4 P_array=( $PIDS )
5 echo $PIDS
6 let "instances = ${#P_array}-1"
7
8 echo "$instances instance(s)" of this script running."
9... (4 Replies)
I need to install a tomcat6 with multiple instances like instance1,instance2 and instance3 in a server.
I came to know that for that we need to install tomcat6,apache2.0,mod_jk1.2 and jre with tools.jar installed.And we need to create multiple instances with same web.xml and difference... (0 Replies)
Hi all,
i have a small script to remove locks for the prevous day and create new lock for processing in the path on my server
i have made something like this
#!/bin/sh
#lock_remover
#script to remove regular lockfiles and hang
curr_month=`date "+%b"`
2day=`date "+%_d"`
cd... (4 Replies)
I wrote two shell scripts in UNIX that renames the same file and scheduled them at the same time.
The following are the steps that I followed:-
1. I wrote 2 scripts named s1.sh and s2.sh, both trying to add “exec_” prefix to the name of the files present in a folder i which already don't start... (4 Replies)
Hi all,
i have compiled a script as below. Basically this script is intended to call 3 other scripts, which i intend to run simultaneously.
#!/usr/bin/bash
HOMEDIR=/path/of/home
LOCKDIR=$HOMEDIR/lock
#check for LOCK
LOCKFILE=$LOCKDIR/$(basename $0 .sh).lock
if ; then
echo... (2 Replies)
Discussion started by: nms
2 Replies
LEARN ABOUT MINIX
uuidd
UUIDD(8) System Administration UUIDD(8)NAME
uuidd - UUID generation daemon
SYNOPSIS
uuidd [options]
DESCRIPTION
The uuidd daemon is used by the UUID library to generate universally unique identifiers (UUIDs), especially time-based UUIDs, in a secure
and guaranteed-unique fashion, even in the face of large numbers of threads running on different CPUs trying to grab UUIDs.
OPTIONS -d, --debug
Run uuidd in debugging mode. This prevents uuidd from running as a daemon.
-F, --no-fork
Do not daemonize using a double-fork.
-k, --kill
If currently a uuidd daemon is running, kill it.
-n, --uuids number
When issuing a test request to a running uuidd, request a bulk response of number UUIDs.
-P, --no-pid
Do not create a pid file.
-p, --pid path
Specify the pathname where the pid file should be written. By default, the pid file is written to /run/uuidd/uuidd.pid.
-q, --quiet
Suppress some failure messages.
-r, --random
Test uuidd by trying to connect to a running uuidd daemon and request it to return a random-based UUID.
-S, --socket-activation
Do not create a socket but instead expect it to be provided by the calling process. This implies --no-fork and --no-pid. This
option is intended to be used only with systemd(1). It needs to be enabled with a configure option.
-s, --socket path
Make uuidd use this pathname for the unix-domain socket. By default, the pathname used is /run/uuidd/request. This option is pri-
marily for debugging purposes, since the pathname is hard-coded in the libuuid library.
-T, --timeout number
Make uuidd exit after number seconds of inactivity.
-t, --time
Test uuidd by trying to connect to a running uuidd daemon and request it to return a time-based UUID.
-V, --version
Output version information and exit.
-h, --help
Display help screen and exit.
EXAMPLE
Start up a daemon, print 42 random keys, and then stop the daemon:
uuidd -p /tmp/uuidd.pid -s /tmp/uuidd.socket
uuidd -d -r -n 42 -s /tmp/uuidd.socket
uuidd -d -k -s /tmp/uuidd.socket
AUTHOR
The uuidd daemon was written by Theodore Ts'o <tytso@mit.edu>.
SEE ALSO uuid(3), uuidgen(1)AVAILABILITY
The uuidd daemon is part of the util-linux package and is available from the Linux Kernel Archive <https://www.kernel.org/pub/linux/utils
/util-linux/>.
util-linux July 2014 UUIDD(8)