title: bash lsof : get pid from one tty to another one
body: <p>How to get the pid in tty1 of the process launched in tty2 ?</p>
  
  <p>Context :<br>
  Trying to write a bash one-liner to kill a process generating a file when this file exceeds a pre defined max size. (The one-liner is not operating yet as it is as need to embed this into a loop).</p>
  
  <p>During testing, the point is that <em>lsof</em> does not return any PID in the terminal tty1 despite the pid exists in the tty2 where the command is run.</p>
  
  <p>tty1: generating the file and monitoring changes</p>
  
  <pre><code>MAX_SIZE_Ko=10001;file=test_lsof;dd if=/dev/zero of=$file bs=1k count=800;inotifywait $file;SIZE_Ko=$(du -s $file | cut -f1); [[ "$SIZE_Ko" -gt "$MAX_SIZE" ]] &amp;&amp; ( PID=$(lsof $file | tail -n1 | awk -F" " '{ print $2 }') ; [[ ! -z $PID ]] &amp;&amp; kill -9 $PID || echo "no running PID modifying $file" )
  </code></pre>
  
  <p>tty2 : increasing the file size</p>
  
  <pre><code>for (( 1; 1; 1));do echo -e "foobar\n" &gt;&gt; test_lsof; echo $(( i++ ))" - pid="$$; done
  </code></pre>