Maximum PID in Linux

It’s 32768 by default, you can read the value on your system in /proc/sys/kernel/pid_max. And you can set the value higher on 64-bit systems (up to 222 = 4,194,304) with: echo 4194304 > /proc/sys/kernel/pid_max Read more here: http://www.cs.wisc.edu/condor/condorg/linux_scalability.html (via archive.org)

Must my pidfile be located in /var/run?

I wouldn’t put a pidfile under an application installation directory such as /opt/my_app/whatever. This directory could be mounted read-only, could be shared between machines, could be watched by a daemon that treats any change there as a possible break-in attempt… The normal location for pidfiles is /var/run. Most unices will clean this directory on boot; … Read more

Linux PID recycling [closed]

As new processes fork in, PIDs will increase to a system-dependent limit and then wrap around. The kernel will not reuse a PID before this wrap-around happens. The limit (maximum number of pids) is /proc/sys/kernel/pid_max. The manual says: /proc/sys/kernel/pid_max (since Linux 2.5.34) This file specifies the value at which PIDs wrap around (i.e., the value … Read more

What is the best way to ensure only one instance of a Bash script is running? [duplicate]

Advisory locking has been used for ages and it can be used in bash scripts. I prefer simple flock (from util-linux[-ng]) over lockfile (from procmail). And always remember about a trap on exit (sigspec == EXIT or 0, trapping specific signals is superfluous) in those scripts. In 2009 I released my lockable script boilerplate (originally … Read more