You can create a Launch Daemon and install it. You should go through the following procedure:
Create your program (a normal executable with
main()
etc.) and put it into one of the standard executable paths. I suggest you use/usr/libexec/
for this purpose.Create a property list in
/System/Library/LaunchDaemons/
of which the name is an arbitrary bundle ID (e. g.com.mycompany.NastyLaunchDaemon.plist
), and its contents are the following:
<plist>
<dict>
<key>Label</key>
<!-- this needs to match the file name without the .plist extension! -->
<string>com.mycompany.NastyLaunchDaemon</string>
<key>Program</key>
<string>/usr/libexec/mynastylaunchd</string>
<key>RunAtLoad</key>
<true />
</dict>
</plist>
After you reboot your device, the program will run.