27

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!

  • 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. – user588 Oct 27 '10 at 0: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 2: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). forums.macrumors.com/showthread.php?t=118545 – Richard Herron Oct 27 '10 at 2:13
  • there is no built-in gui solution that i know of... – Robert S Ciaccio Oct 27 '10 at 3:29
  • OK, thanks, All! When I write a good script, I'll post it back here. – Richard Herron Oct 27 '10 at 3:51
22

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
  • 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 5 '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 6 '10 at 0: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 iki.fi/era/unix/award.html#grep – tripleee Jul 8 '15 at 18:19
  • 1
    just fix a typo in your updated command, reads sudu should read sudo. – hoss Sep 26 '15 at 14:10
18

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.

  • 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
7

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

  • Seems to me this is a clearly better and more idiomatic answer (from a unix sysadmin standpoint) than the others. – Gregg Leventhal Jul 26 '18 at 1:10
2

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

  • 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 at 10:01
-1

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.

  • 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .