TL;DR
- You typically want to use
launchctl load -w
and launchctl unload -w
.
start
and stop
are usually reserved for testing or debugging a job.
Details
launchctl start <label>
: Starts the job. This is usually reserved just for testing or debugging a particular job.
launchctl stop <label>
: Stops the job. Opposite of start, and it's possible that the job will immediately restart if the job is configured to stay running.
launchctl remove <label>
: Removes the job from launchd
, but asynchronously. It will not wait for the job to actually stop before returning, so no error handling on this one.
launchctl load <path>
: Loads and starts the job as long as the job is not "disabled."
launchctl unload <path>
: Stops and unloads the job. The job will still restart on the next login/reboot.
launchctl load -w <path>
: Loads and starts the job while also marking the job as "not disabled." The job will restart on the next login/reboot.
launchctl unload -w <path>
: Stops and unloads and disables the job. The job will NOT restart on the next login/restart.
Where do I find the job label for a daemon, is it in the plist file?
Yes, it's in the plist file and it typically matches the filename of the plist file.
Resume, counterintuitively, does not actually save anything itself. It simply relaunches all the applications that were running when you shut your computer down. It's the job of those Lion-compatible applications to restore their windows.
Safe sleep, on the other hand, saves a snapshot of your RAM to your HDD when you put your computer to sleep. In case of power failure, the machine boots from this file on startup.
Safe sleep is the only time (that I know of) that OS X saves its RAM.
You can use the pmset
command line utility (specifically the sudo pmset -a hibernatemode x
command where x
is the sleep mode) to change the sleep mode, although there is no significant benefit in doing this.
The three main different kinds of sleep are as follows (from the pmset
man
page):
hibernatemode = 0 (binary 0000) by default on supported desktops. The
system will not back memory up to persistent storage. The
system must wake from the contents of memory; the system will lose context on power loss. This is, historically, plain old sleep.
hibernatemode = 3 (binary 0011) by default on supported portables. The system will store a copy of memory to persistent
storage
(the disk), and will power memory during sleep. The system will wake from memory, unless a power loss forces it to restore from
disk image.
hibernatemode = 25 (binary 0001 1001) is only settable via pmset. The system will store a copy of memory to persistent storage
(the disk), and will remove power to memory. The system will restore from disk image. If you want "hibernation" - slower sleeps,
slower wakes, and better battery life, you should use this setting.
As I stated before, configuring the sleep mode is not recommended (again from the pmset
man
page):
We do not recommend modifying hibernation settings. Any changes you
make are not supported. If you choose to do so anyway, we recommend
using one of these three settings. For your sake and mine, please
don't use anything other 0, 3, or 25.
I don't know about the script vs. user issue, although I highly doubt there is a difference.
Best Answer
In the shell, ulimit provides "control over the resources available to the shell and to processes started by it" (see
man bash
). Therefore, it applies only to the shell and its children. The limits for launchd are related to it and the processes that it manages. The two are separate.Individual programs can set their own resource limits by calling the Standard C Library routines
ulimit()
orgetrlimit()
andsetrlimit()
. Certain resource limits cannot be elevated unless the process is running as the super-user.As a practical example, I debug large software projects and the shell's default limit for the number of open files isn't big enough. In my .bashrc file, I have the following:
Now my debugger won't complain that it can't open all the files it needs. Obviously, this should have no impact on launchd.