#!/bin/bash

# Define a unique lock file path
LOCKFILE="/tmp/my_script.lock"

# Open the lock file (or create it if it doesn't exist) on file descriptor 9
exec 9>"$LOCKFILE"

# Apply an exclusive, non-blocking lock on file descriptor 9
if ! flock -xn 9; then
    echo "ERROR: Script is already running." >&2
    exit 1
fi

# Set a trap to ensure the lock file is removed if the script exits unexpectedly
trap 'rm -f "$LOCKFILE"' EXIT

# The rest of your script goes here
echo "Lock acquired, running the main part of the script..."

/usr/bin/php process.php


sleep 1
echo "Finished."

# The lock is automatically released when the script exits, 
# and the trap ensures the file is removed.
