title: Get the process ID in a Shell script when a process is launched in foreground
body: <p>In a shell program I want to launch a program and get its PID and save in a temp file. But here I will launch the program in the foreground and will not exit the shell until the process is in running state </p>
  
  <p>ex:</p>
  
  <pre><code> #!/bin/bash
  
   myprogram &amp;
   echo "$!"  &gt; /tmp/pid
  </code></pre>
  
  <p>And this works fine i am able to get the pid of the launched process . But if i launch the program in fore ground i want to know how to get the pid </p>
  
  <p>ex :</p>
  
  <pre><code>#!/bin/bash
  
  myprogram       /// hear some how i wan to know the PID before going to next line
  </code></pre>