title: Get the pid of the shell script and save it into a lockfile
body: <p>I do my backups with rsnapshot which creates a lockfile with the process pid inside. Now I would like to make a backup from the rsnapshots backup, so I´m looking for a way to create this lockfile for the second/external backup.</p>
  
  <p>The shell script should like this:</p>
  
  <ol>
  <li>check if a lockfile exists, if yes wait and try again(i´m doing this with a while true loop)</li>
  <li>get the pid of this shell script and save it as a rsnapshot lockfile</li>
  <li>start the second/external backup</li>
  <li>delete the lockfile</li>
  </ol>
  
  <p>How can I get the PID and save it as a rsnapshot lockfile ?</p>