39

My wife use separate accounts and quick user switching on a MBP running 10.6. Sometimes I want to log her out to free up some RAM, but I'd like to avoid logging in as her, logging out, then logging back in as me.

I have seen a terminal solution... is there a better way? Thanks!

Dori
  • 7,217
  • 1
  • 32
  • 40
Richard Herron
  • 739
  • 2
  • 6
  • 9
  • 5
    You need to better define "is there a better way". For me, not much (computer-wise) is better than a terminal. If you want an app, just wrap the terminal command in an automator or applescript app. –  Oct 27 '10 at 00:47
  • 2
    @mankoff, good point! But this isn't an Arch Linux forum, so let's assume I want a GUI/built-in solution :). But, you're right, I can just write a shell script. – Richard Herron Oct 27 '10 at 02:12
  • 2
    Here is the link to the script solution (I saw it before posting, but it's from 2005, so I assumed that by now this simple feature must have been incorporated into the GUI). http://forums.macrumors.com/showthread.php?t=118545 – Richard Herron Oct 27 '10 at 02:13
  • there is no built-in gui solution that i know of... – Robert S Ciaccio Oct 27 '10 at 03:29
  • OK, thanks, All! When I write a good script, I'll post it back here. – Richard Herron Oct 27 '10 at 03:51
  • Wives and RAMs can't pleasure you together. You have to choose one. Now where's the script – nonocut Aug 17 '15 at 15:43
  • Nothing is "better" than a terminal command when it comes to telling your computer to do something. – Gregg Leventhal Jul 26 '18 at 01:12
  • This is a very good question, if not phrased very well. All suggester "Terminal" solutions tell you to kill some process (loginwindow) of the user you want to log out - but that's BAD because it does not do the normal flow of logout, which allows user apps to save their data etc. Also - being an "Admin" on a multi-account/multi-user Mac calls for some reasonable UI for managing user sessions. I believe this is the actual question, – Motti Shneor Jun 16 '21 at 08:17

5 Answers5

29

Using the Terminal, you can kill her loginwindow process and any programs she has open will be closed... but this will cause her to lose any unsaved work she has! In fact, this is the very reason you need to log in as her to log out: When you log in as her, all her programs again have access to the GUI, so they can prompt you to confirm closure, save changes or take other action before logging out.

If you're sure that she only has things like a web browser, iTunes, etc open, not Pages, Word, Photoshop, or anything else with documents, then you could try from the terminal:

kill `ps awwwwux | grep her_short_username | grep loginwindow | grep -v grep | awk "{ print \$2 }"`

On OSX 10.10.4: (slight edit from last comment):

export pn=`ps awwwwux | awk '/her_short_username/ && /loginwind[o]w/ { print $2 }'`
sudo kill -9 $pn
Josh
  • 8,449
  • 15
  • 40
  • 59
  • 1
    Agree with the warning that if you don't log in to see what she's doing, then you don't know what you might cost her by logging her out. – Michael H. Nov 05 '10 at 17:49
  • Yeah, you're right. Most of the time it's web-browsing... But one time it won't be! Thanks! – Richard Herron Nov 06 '10 at 00:58
  • 4
    If you force-terminate her `loginwindow` through `Activity Monitor.app` you could conveniently glance at the same time what other processes she has left open. – Jari Keinänen Jul 29 '11 at 11:54
  • 1
    If you end up running Awk anyway, the multiple `grep` commands can easily be avoided. `ps awwwwux | awk '/her_short_username/ && /loginwind[o]w/ { print $2 } | xargs kill` and see also http://www.iki.fi/era/unix/award.html#grep – tripleee Jul 08 '15 at 18:19
  • That's a much better command line @tripleee, I agree. My awk wasn't as good 5 years ago :-) – Josh Jul 09 '15 at 00:53
  • 1
    just fix a typo in your updated command, reads `sudu` should read `sudo`. – hoss Sep 26 '15 at 14:10
  • Is that 10.10.4 only, or 10.10.4 and up? – ebrts May 16 '17 at 00:23
27

You can use the Activity Monitor to log another user out by killing their login process:

  1. Run Activity Monitor
  2. In the filter at the top-right, type loginwindow
  3. Click the row with the user's name in the User column
  4. Click Quit Process, then Force Quit, and type your password.

This is just a nicer(?) GUI version of Josh's answer.

Before step 2, you can review the other user's running processes to see if they are running any apps that might lose data on logout.

Bennett McElwee
  • 436
  • 5
  • 6
  • 1
    I tried this and still see the other user's processes running in Activity Monitor. True, the account appear logged out in the user switching menu, but it doesn't seem to be truly the same thing as logging out. – Gorb Jul 15 '18 at 16:09
  • Same. Maybe this doesn't work in a more current OS than Bennet was using – jcollum Apr 01 '20 at 23:23
  • As of MacOS Mojave it still works. I notice that even when you actually log out the other user normally, there are still over 20 processes running under that user. The same thing happens if you force-quit loginwindow. – Bennett McElwee Mar 16 '21 at 02:18
18

This command is simpler than the one suggested and it will have the desire result to kill all the user's processes (I had to run it twice)

sudo pkill -9 -u user

If you just want to kill the loginwindow process for that user you can do the following:

sudo pkill -9 -u user loginwindow

Ulukai
  • 281
  • 2
  • 3
4

I think the simplest way of doing it is : sudo killall -9 -u wifes_name

mempman
  • 41
  • 1
  • Using MacOS Mojave, this is the only solution after trying many which not only killed the LoginWindow process, but many other processes owned by that user. Killing the LoginWindow process for that user alone didn't kill many other processes started by that user. This solution (replacing with my wife's name) got rid of every single process started by her login. Akin to rebooting the machine and just logging in yourself. – i-CONICA Mar 16 '19 at 10:01
-2

In my opinion, the possible loss of data far outweights the possible gain in RAM.

Moreover, it has been a long time since Unix was able to swap memory to disk when a process was idle.

mouviciel
  • 1,439
  • 2
  • 15
  • 15
  • 2
    One problem is that when a user is switched out, their processes may not be idle. They may be chewing up CPU and memory. Games seem particularly bad in this respect. – Bennett McElwee Mar 12 '15 at 20:59
  • 2
    Question mentions the wife, but there is actually an even better case - when you have a child that has exceed their time limit for the day and only plays games and does other things that don't need saving. Now not only do you have to log in as the kid but add time just to log them out. – Michael Jul 25 '15 at 16:28
  • @Michael That is exactly _my_ use case. :) – Bennett McElwee Aug 24 '15 at 23:40