How to show a list of processes that are launched upon a login?

There are some processes that are launched upon a login, how to get a list of these processes?
I want to prevent some processes from being launched automatically.


Solution 1:

launchd and the Login Items pane of Accounts preferences are the two places that normally start a process when you log in.

If you don't see the item in System Preferences -> Accounts -> specific account -> Login Items then you will have to look into launchd.

Basically the LaunchAgents and LaunchDaemons folders in ~/Library

Lastly, if they are not there, then it's a system level launchd task that you might want to use launchctl to show or look in /Library instead of the user level library.

Most people just have to manage the preference pane. Here is a snap of mine showing the Activity Monitor selected and ready to be deleted if I press the button. enter image description here

Solution 2:

You need to investigate launchctl(1) because there are a couple of contexts you will need to account for .

The easiest way is to look at the plist files in:

/System/Library/LaunchDaemons # System Context. Faceless. root lives here. /System/Library/LaunchAgents # Loginwindow, or Aqua, where you live, context /Library/LaunchDaemons /Library/LaunchAgents ~/Library/LaunchDaemons ~/Library/LaunchAgents

In the file you will see the default state of that daemon or agent. That is a sure way to tell if it is running at boot.

I mention the above degrading, foolish and time consuming method, because it is good to see all the stuff running. They claim the resources used are low for a loaded yet dormant daemon, but since 95%+ of them are set to RunOnDemand... to me that's running.

Don't actually do that for real though. There is a much easier way.

Remember

When you log in and open Terminal/iTerm, you are in Aqua context.

Loginwindow context is when you see the login window, unsurprisingly, and a ton of things run off that.

If you

sudo zsh  # why not be comfortable?

or some other method to get a root shell, the root user will be in System context, which is the context that all the daemons in /System/Library/LaunchDaemons run in.

I mention all this because the tool provided:

man 1 launchctl

has a verb,

launchctl list

which you might think from the man page, lists all the running services. You might feel it plausible, to switch to root, to get a higher level view of what runs when you login.

Sadly, each user sees his own context.

launchctl managername 

will tell you what it is.

For root, its System. From my nifty hidden admin user, it's Background, which is the same thing you get by typing

>console

into the username box for login

You can use the verb

launchctl bslist  

Which tells you what services are active, for you. It's different for _spotlight, for the hidden admin, for root, for macports etc.

Answer

The command to see the whole tree, is

sudo launchctl bstree [-j]

whatever you see when you run that after booting is what is running system wide. For your identity:

launchctl bslist