Skip to main content
added 49 characters in body
Source Link
user1146332
  • 2.3k
  • 13
  • 15

If you want to make sure that only one instance of your script is running take a look at:

Lock your script (against parallel run)

Otherwise you can check ps or invoke lsof <full-path-of-your-script>, since i wouldn't call them additional tools.


Supplement:

actually i thought of doing it like this:

for LINE in `lsof -c <your_script> -F p`; do 
    if [ $$ -gt ${LINE#?} ] ; then
        echo "'$0' is already running" 1>&2
        exit 1;
    fi
done

this ensures that only the process with the lowest pid keeps on running even if you fork-and-exec several instances of <your_script> simultaneously.

If you want to make sure that only one instance of your script is running take a look at:

Lock your script (against parallel run)

Otherwise you can check ps or invoke lsof <full-path-of-your-script>, since i wouldn't call them additional tools.


Supplement:

actually i thought of doing it like this:

for LINE in `lsof -c <your_script> -F p`; do 
    if [ $$ -gt ${LINE#?} ] ; then
        exit 1;
    fi
done

this ensures that only the process with the lowest pid keeps on running even if you fork-and-exec several instances of <your_script> simultaneously.

If you want to make sure that only one instance of your script is running take a look at:

Lock your script (against parallel run)

Otherwise you can check ps or invoke lsof <full-path-of-your-script>, since i wouldn't call them additional tools.


Supplement:

actually i thought of doing it like this:

for LINE in `lsof -c <your_script> -F p`; do 
    if [ $$ -gt ${LINE#?} ] ; then
        echo "'$0' is already running" 1>&2
        exit 1;
    fi
done

this ensures that only the process with the lowest pid keeps on running even if you fork-and-exec several instances of <your_script> simultaneously.

added 380 characters in body
Source Link
user1146332
  • 2.3k
  • 13
  • 15

If you want to make sure that only one instance of your script is running take a look at:

Lock your script (against parallel run)

Otherwise you can check ps or invoke lsof <full-path-of-your-script>, since i wouldn't call them additional tools.


Supplement:

actually i thought of doing it like this:

for LINE in `lsof -c <your_script> -F p`; do 
    if [ $$ -gt ${LINE#?} ] ; then
        exit 1;
    fi
done

this ensures that only the process with the lowest pid keeps on running even if you fork-and-exec several instances of <your_script> simultaneously.

If you want to make sure that only one instance of your script is running take a look at:

Lock your script (against parallel run)

Otherwise you can check ps or invoke lsof <full-path-of-your-script>, since i wouldn't call them additional tools.

If you want to make sure that only one instance of your script is running take a look at:

Lock your script (against parallel run)

Otherwise you can check ps or invoke lsof <full-path-of-your-script>, since i wouldn't call them additional tools.


Supplement:

actually i thought of doing it like this:

for LINE in `lsof -c <your_script> -F p`; do 
    if [ $$ -gt ${LINE#?} ] ; then
        exit 1;
    fi
done

this ensures that only the process with the lowest pid keeps on running even if you fork-and-exec several instances of <your_script> simultaneously.

Source Link
user1146332
  • 2.3k
  • 13
  • 15

If you want to make sure that only one instance of your script is running take a look at:

Lock your script (against parallel run)

Otherwise you can check ps or invoke lsof <full-path-of-your-script>, since i wouldn't call them additional tools.