When was Linux -/proc/PID created?

When was Linux -/proc/PID created? … here is a solution to the problem.

When was Linux -/proc/PID created?

I’m writing a Bash script to monitor the process and detect when it crashes. I’m monitoring the /proc directory for this;

start_my_process;
my_process_id=$!;
until [[ ! -d "/proc/$my_process_pid" ]]; do
   # alert the process is dead and restart it...
done

Can I guarantee that the process entry in /proc/ is created before Bash finishes executing the command to start the process? Or is it possible that when I perform the above check, I may not have created an entry for start_my_process?

Edit:
In the end, I actually objected to custom solutions and chose monit, which is an excellent watchdog tool.

Solution

/

proc/<pid> will never be created. It is not really a directory.

/proc is a virtual file system. When you open one of these “files” and read from its output stream, the data is provided by the kernel. Since the kernel is also responsible for managing processes <pid>, the kernel will tell you that /proc/<pid> directory exists as long as the kernel keeps track of the directory.

Because bash can’t set $! You can definitely safely check the process virtual directory under /proc before the process exists. After that.

Related Problems and Solutions