Dear Readers, I'm trying to get the following command launched by launchd on system startup
while `sleep 4`; do echo **clunk** > /tmp/declunk && rm -f /tmp/ declunk; done &
I created a bash script /usr/bin/declunk with 1 #!/bin/bash 2 while `sleep 4`; do echo **clunk** > /tmp/declunk && rm -f /tmp/ declunk; done & And than create the following launchd plist in /Library/LaunchDaemons 1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd "> 3 <plist version="1.0"> 4 <dict> 5 <key>Disabled</key> 6 <false/> 7 <key>KeepAlive</key> 8 <false/> 9 <key>Label</key> 10 <string>de.tiggar.declunk</string> 11 <key>ProgramArguments</key> 12 <array> 13 <string>/usr/bin/declunk</string> 14 </array> 15 <key>RunAtLoad</key> 16 <true/> 17 <key>StartOnMount</key> 18 <false/> 19 </dict> 20 </plist> Next i try to load the agent with:
Sep 16 22:03:00 iah sudo[7855]: Jan : TTY=ttys000 ; PWD=/ Library/LaunchDaemons ; USER=root ; COMMAND=/bin/launchctl load -w de.tiggar.declunk.plist Sep 16 22:03:00 iah com.apple.launchd[1] (de.tiggar.declunk[7861]): Stray process with PGID equal to this dead job: PID 7863 PPID 7862 sleep Sep 16 22:03:00 iah com.apple.launchd[1] (de.tiggar.declunk[7861]): Stray process with PGID equal to this dead job: PID 7862 PPID 1 bash
So the question is now. It is possible to have a script like that work with launchd? What do I have done wrong? Thanks for your help. Cheers, Jan
At 22:05 +0200 16/9/08, Jan Michael wrote:
So the question is now. It is possible to have a script like that work with launchd? What do I have done wrong?
The problem here is that a process started by your script is outliving your script. launchd detects this are automatically garbage collects the errant process. This is discussed in detail in the "Careful With That Fork, Eugene" section of TN2083. <http://developer.apple.com/technotes/tn2005/tn2083.html> In this specific case the problem is the ampersand at the end of line 2 of your script. That causes the contents of line 2 to run in the background. The script then exits, launchd detects the stray process, and cleans them up. It looks like your script is meant to run forever. In that case, you don't need the ampersand. S+E -- Quinn "The Eskimo!" <http://www.apple.com/developer/> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
Quinn, many thanks for the tip and also pointing out the TN. Cheers, Jan On 17.09.2008, at 10:51, Quinn wrote:
At 22:05 +0200 16/9/08, Jan Michael wrote:
So the question is now. It is possible to have a script like that work with launchd? What do I have done wrong?
The problem here is that a process started by your script is outliving your script. launchd detects this are automatically garbage collects the errant process. This is discussed in detail in the "Careful With That Fork, Eugene" section of TN2083.
<http://developer.apple.com/technotes/tn2005/tn2083.html>
In this specific case the problem is the ampersand at the end of line 2 of your script. That causes the contents of line 2 to run in the background. The script then exits, launchd detects the stray process, and cleans them up. It looks like your script is meant to run forever. In that case, you don't need the ampersand.
S+E -- Quinn "The Eskimo!" <http://www.apple.com/developer/
Apple Developer Relations, Developer Technical Support, Core OS/ Hardware _______________________________________________ launchd-dev mailing list launchd-dev@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/launchd-dev
participants (2)
-
Jan Michael
-
Quinn