How to restart the desk top from the terminal? . .

Posted:
in macOS edited January 2014
My machine got stuck after using a utility to back up my preferences. I have Escape Pod installed and it would not kill off the stuck Finder. So logged in remotely from my PC in a terminal window as "root" and type "reboot" and the system obeyed perfectly.



But is there a command to reboot just the desktop with out rebooting the whole machine?



Thanks!



-Scott

Comments

  • Reply 1 of 8
    der kopfder kopf Posts: 2,275member
    Several ways, assuming you actually mean the (application) Finder when you say desktop.



    You can go in the dock, right-click the Finder icon and choose "relaunch" (an option that'll show up if the Finder is indeed gone to Pablo).



    If that don't work, you can try the intricate key-combo alt-cmd-esc, to bring up the force quit dialog, where you can choose to relaunch the finder as well.



    If that don't work, you can open up Terminal (an application in the Utilities folder), where it may be good to open up two windows. In one, you type 'top' followed by enter, you then look up the PID of the Finder process (should be high up there if the finder is hung), you then use that PID (process ID, usually a three or four digit number) in the following command:



    sudo kill <pid of the finder>



    where you put the PID in the appropriate place. (it will ask you for the password).



    The Finder should then quit (immediately). After which it normally relaunches automatically. Alternately, you can go in the dock and click the finder icon to relaunch it.
  • Reply 2 of 8
    Quote:

    Originally posted by der Kopf

    Several ways, assuming you actually mean the (application) Finder when you say desktop.



    You can go in the dock, right-click the Finder icon and choose "relaunch" (an option that'll show up if the Finder is indeed gone to Pablo).



    If that don't work, you can try the intricate key-combo alt-cmd-esc, to bring up the force quit dialog, where you can choose to relaunch the finder as well.



    If that don't work, you can open up Terminal (an application in the Utilities folder), where it may be good to open up two windows. In one, you type 'top' followed by enter, you then look up the PID of the Finder process (should be high up there if the finder is hung), you then use that PID (process ID, usually a three or four digit number) in the following command:



    sudo kill <pid of the finder>



    where you put the PID in the appropriate place. (it will ask you for the password).



    The Finder should then quit (immediately). After which it normally relaunches automatically. Alternately, you can go in the dock and click the finder icon to relaunch it.




    Hi Der Kopf,



    In this case the desktop/Finder was really out to lunch. The program I was running ("Back up user prefs 2.4.8") croaked and when it went away, so did all the desktop icons. I was left with the menu bar, and the Dock and the spining pizza wheel of death.



    Great suggestions for what to do from the terminal. I should have though about running TOP.



    This has happened before, and most of the time Escape Pod has worked well, but this time and one or two other times it didn't. I enabled the root account so I could login remotely for this very reason, to reboot the system if all else failed. Last time I tryed logging remotely, I was logging in under my account, I couldn't do anything as I was told "you don't have permission to do that" blah, blah. So at least this time I didn't have to hold the power button in till it shutoff. It also started a lot faster from the reboot vs. hard shutdown (powering off.)



    -Scott
  • Reply 3 of 8
    bartobarto Posts: 2,246member
    Did you try typing control+option+command+delete in Escape Pod?



    That should log you out.



    control+option+shift+delete should kill the dock too (maybe that was causing the hang - it has done for me in the past).



    As many people will tell you, enabling the root account is a bad thing to do. Seriously. It's much better to log in as yourself, and type "sudo" before any command ( eg sudo cp someFile /some/folder/elsewhere/ ).



    As far as figuring out what process is causing the hang, yeah use top to see what proccesses are yours, and kill off the most likely ones (and of course any "zombie" processes).



    Barto



    PS thank you so much Moki for EscapePod



    [edit by Brad: removed potentially harmful command]
  • Reply 4 of 8
    baumanbauman Posts: 1,248member
    you'll want to use 'top -u' so it sorts to the highest CPU usage.



    sudo works just as well as root, only with a less danger... unless you try Barto's example!



    if sudo kill <pid> doesn't seem to work, try sudo kill -9 <pid>. That should really get rid of it.



    If you ever kill a part of the OS, and it doesn't automatically restart, go to /System/Library/CoreServices/ and you can start the Finder, Dock, and such from there simply by double clicking.
  • Reply 5 of 8
    bartobarto Posts: 2,246member
    Quote:

    Originally posted by bauman

    sudo works just as well as root, only with a less danger... unless you try Barto's example!



    Hehe.... sorry 'bout that. On second thoughts, it was probably a bad idea to post that even with the warning (thanks Brad).



    Barto
  • Reply 6 of 8
    So I can use the sudo to get the same results as being logged it as root?



    Just tried "sudo" and it worked (asked for my password!) Ok that's great, I will disable my root account right now. Now I'm finally clear on "sudo" and how to use it.



    Thanks everyone. I'm all set for the next Finder hang up!



    -Scott
  • Reply 7 of 8
    pbpb Posts: 4,255member
    Quote:

    Originally posted by scott_r





    Thanks everyone. I'm all set for the next Finder hang up!



    -Scott




    After such a hang up, don't forget to manually run fsck, since the automated disk check during startup may not repair disk damage completely. If your computer is running, type in the terminal: sudo shutdown now. After that, you will see the traditional black unix screen with a command prompt. Then you simply type: fsck -y. If the system reports modifications in the disk structure, repeat the 'fsck -y' command until it says it is OK. Then type: reboot. You can also enter in the 'black screen mode' if during startup you press and hold the keys 'cmd' and 's'.
  • Reply 8 of 8
    der kopfder kopf Posts: 2,275member
    Actually, if you really want to do it the nice way, you'd want the use the ps command, as followed:



    Code:


    ps -acx | grep Finder







    This will show only the pid of the Finder process and deliver you back to the prompt (unlike top). That vertical line is indeed a vertical line (a unix 'pipe', by which you 'chunnel' the output of one command to a next command where it can be used again). I make it on my keyboard (layout azerty) by alt+l (that's an L).

    After that command, you execute the kill, ...
Sign In or Register to comment.