\begin{exe} {Changing the Maximum Process ID}

   The normal behavior of a \textbf{Linux} system is that
   process IDs start out at \verb?PID=1? for the
   \textbf{init} process, the first user process on the
   system, and then go up sequentially as new processes are
   constantly created (and die as well.)

   However, when the PID reaches the value shown in
   \url{/proc/sys/kernel/pid_max}, which is
   conventionally 32768 (32K), they will wrap around to lower
   numbers.  If nothing else, this means you can't have more
   than 32K processes on the system since there are only
   that many slots for PIDs.

   \begin{enumerate}
      \item
      Obtain the current maximum PID value.
      \item
      Find out what current PIDs are being issued
      \item
      Reset \verb?pid_max? to a lower value than the ones currently
      being issued.
      \item
      Start a new process and see what it gets as a PID.
   \end{enumerate}
   \begin{sol}

      \begin{important}
         In the below we are going to use two methods, one
         involving \textbf{sysctl}, the other directly echoing
         values to \url{/proc/sys/kernel/pid_max}.  Note that
         the \textbf{echo} method requires you to be root;
         \textbf{sudo} won't work.  We'll leave it to you to
         figure out why, if you don't already know!
      \end{important}
      \begin{enumerate}
         \item
         \begin{cmd}
$ sysctl kernel.pid_max
$ cat /proc/sys/kernel/pid_max
         \end{cmd}
         \item
         Type:
         \begin{cmd}
$ cat &
         \end{cmd}
         \begin{response}
[1] 29222
         \end{response}
         \begin{cmd}
$ kill -9 29222
         \end{cmd}
         \item
         \begin{cmd}
$ sudo sysctl kernel.pid_max=24000
$ echo 24000 >  /proc/sys/kernel/pid_max # This must be done as root
$ cat /proc/sys/kernel/pid_max
         \end{cmd}
         \item
         \begin{cmd}
$ cat &
         \end{cmd}
         \begin{response}
[2] 311
         \end{response}
         \begin{cmd}
$ kill -9 311
         \end{cmd}
      \end{enumerate}
      \begin{info}
         Note that when starting over, the kernel begins at
         PID=300, not a lower value.  You might notice that
         assigning PIDs to new processes is actually not
         trivial; since the system may have already turned
         over, the kernel always has to check when generating
         new PIDs that the PID is not already in use.  The
         \textbf{Linux} kernel has a very efficient way of
         doing this that does not depend on the number of
         processes on the system.
      \end{info}
   \end{sol}
\end{exe}

