The traditional way Unix daemons handle this problem is with "pid files".
When your program starts up (or when your launcher starts your program up), it creates a file in a well-known location (/var/run/<PROGRAM NAME>.pid
for system daemons; per-user daemons don't have a universal equivalent), writes the PID into that file (as in the ASCII string 12345\n
for PID 12345), and deletes it when it exits. So, you can just kill $(cat /var/run/myprogram.pid)
.
However, it doesn't seem like you need this here. You could easily design the program to be cleanly shutdown, instead of designing it to be killable.
Or, even easier, remove the sleep; instead of having cron run your script it every hour and having the script sleep for a minute at a time until the PDF file is created, just have LaunchServices run the script when the PDF is created.