I in such case use a different UID when having 2 instances of the same program running to differenciate them (different UID - same GID with group set as -rws-on the directories ...)
The traditional way to check if a process is running is PID files. When you start it, arrange for a file containing its PID to be created to reference later. This avoids the ps | awk | grep | sed | cut | kitchen | sink nonsense, and is a lot more portable, and allows you to run more than one of the same thing independently without them conflicting.
#!/bin/sh
# Often /var/run, but only root can write there
MYPIDFILE=/path/to/mypid.pid
if [ -f "$MYPIDFILE" ] && read -r PID "$PIDFILE" && ps "$PIDFILE" >/dev/null
then
echo "Process is still running as PID $PID" >&2
exit
fi
echo "Process is not running." >&2
# If your shell complains about 'disown', then your shell doesn't need it and it can be removed
/path/to/processtostart & disown # Assumes the process does not fork other PIDs
echo "$!" > "$MYPIDFILE"
echo "Now running as PID $!" >&2
exit
It's possible that your daemons are creating PID files somewhere already. Take a look around their files.
What you are saying is to set a variable with the pid of my process and check if it's running based on that pid?
Would that alone solve the problem of parallel processes or do i have to combine this solution with the change of uid?
More specificly, on each of the environments i have this binary folder i have different scripts for verifying the processes, i mean i run them from different paths, being different scripts. They have the same permissions now. Each pair of isProgRunning and runProg to be in the same gid, but have different uid?