Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

carlsson

macrumors 6502a
Original poster
Jul 18, 2001
600
521
To make a long story short, I need a one line command that kills all processes that contains the word "dock".

(Background is that the Dock freezes for me when I disconnect my monitor (it started with beta testing Sonoma), and after spending conuntless hours and days of reinstalling everything from scratch, I can't get rid of this problem (it works as it should with a fresh user, but returns after a couple of days, and now I don't have more time to search for the reason of this behavior).)

So, instead of opening the activity monitor, search for "dock", and kill those processes, I want to make an sh command that just kills them. That way I can create a shortcut with Keyboard Maestro and save a lot of time!
However, I don't know the correct use of 'grep' in combination of 'kill'.

Anyone that can help me?

I have tried with killall Dock, and that works for the Dock, but as you can see on the screenshot I also need to kill Dock-tillbehör, and I got this message when I try to do that: "No matching processes belonging to you were found"
I guess this is because there is an "ö" in the process name.

It's these processes I want to kill:
1701334020622.png
 
From the killall(1) man page:
Code:
   -m   Match the argument procname as a (case sensitive) regular expression against the names of processes found.  CAUTION!  This is dangerous, a single dot will match any process running under the real UID of the caller.
 
Thanks, and I have tried that. However, I can't get it to work properly.

killall -m Dock kills the Dock, nothing else.
killall -m Dock* don't work (no matches found).

I know this is because I'm still a noob in Terminal knowledge… 😝
 
First, you need to put the regular expression into single quotes to prevent the shell from attempting to expand it with its globbing.

Second, the regular expression "Dock*" matches "Doc" followed by an arbitrary number of "k". What you want is "Dock.*".

In other words, don't confuse shell globbing with regular expressions!
 
  • Like
Reactions: frou
Thanks for the input.
The process called "Dock-tillbehör" is called something else when I look at it with top in Terminal.
However, I only see the first letters due to the column is to narrow. "com.apple.dock.e"
So, I thought it was "com.apple.dock.extra", and did a:
killall Dock com.apple.dock.extra

Didn't work.

So I realized I Force quit the process when I'm in Activity Monitor.
But I don't know how to Force quit from the Terminal. Looked at man, couldn't find it. Tried with -f, didn't work.

Any ideas?
 
Code:
# List all processes containing the string 'dock' (ignoring case)
pgrep -ilf dock

# Kill all processes containing the string 'dock' (ignoring case)
pkill -i dock
 
  • Like
Reactions: zevrix
Finally I have a terminal command that works. It looks like this:

killall -KILL Dock com.apple.dock.extra

(the -KILL option I got from a Unix friend)

…and for those that are curious to see how this looks in reality, I have attached a screen recording. While the screen is black I can’t use CMD+Tab to switch application, or use the Dock. I have a shortcut for opening Terminal, that’s why it shows up all of a sudden.
:slight_smile:


Thanks for all inputs!

/FWIW

 
What is that option for? It’s not in the manual (man killall)
It kinda is in the man page, it's the -SIGNAL option.

Code:
% killall
usage: killall [-delmsqvz] [-help] [-I]
               [-u user] [-t tty] [-c cmd] [-SIGNAL] [cmd]...

So in this case, send the SIGKILL signal vs default of SIGTERM.

-SIGNAL Send a different signal instead of the default TERM.
The signal can be specified either as a name (with or without
a leading SIG), or numerically.

"killall -9" should work as well (KILL is 9).

And: kill command is similar, so "kill -9" for a KILL vs TERM.
 
  • Like
Reactions: bogdanw
kill -l (that's an ell) will list the signals in order, starting from 1 (HUP). Signal 9 is sometimes necessary, but should be avoided unless no other signal will do the job because it can't be caught, leaving the target process unable to do any cleanup (removing lock files, for one example).
 
  • Like
Reactions: Basic75 and NoBoMac
man kill
" Some of the more commonly used signals:

1 HUP (hang up)
2 INT (interrupt)
3 QUIT (quit)
6 ABRT (abort)
9 KILL (non-catchable, non-ignorable kill)
14 ALRM (alarm clock)
15 TERM (software termination signal)"
 
LOL, didn't expect this to be listed as "more commonly used" in the 21st century.
Maybe not from a common user standpoint, but from a code perspective, sure.

settimer() and alarm() function calls send that signal after X seconds. So if you have a server/daemon program running, handling stuff/work/requests, might want to set an alarm for the program to do something else every say 30 seconds (check on something, purge something, create a rollback log, etc), use one of the functions to generate the signal. Signal handler to capture the SIGALRM and handle accordingly.

Maybe an admin shell script to send that signal via kill occasionally to do something extra while service running?
 
after spending conuntless hours and days of reinstalling everything from scratch, I can't get rid of this problem (it works as it should with a fresh user, but returns after a couple of days,
You've established that it's a user-based issue; so no amount of reinstalling will fix it.

The cause will be either some settings in your user account (which includes processed that are set to launch eg. at startup); or possibly some corrupt caches. I'd try removing any third-party 'menulet' apps you might have, first of all.

Killing Dock processes may stop the problem, but it's not ideal; and long-term you need to figure out the cause.
 
You've established that it's a user-based issue; so no amount of reinstalling will fix it.

The cause will be either some settings in your user account (which includes processed that are set to launch eg. at startup); or possibly some corrupt caches. I'd try removing any third-party 'menulet' apps you might have, first of all.

Killing Dock processes may stop the problem, but it's not ideal; and long-term you need to figure out the cause.

I hear you. However, at the time, I really don't have more time to test this.
Since forever it has been quite easy to troubleshoot these kind of errors, but something is really weird this time. I suspect that Rosetta is involved in combination with something else, but I have two things that need Rosetta so I'm out of options at this moment.
Shortcut COM+OPT+CTRL+F12 triggers the shell script. Easy workaround at the moment, even though my OCD goes bananas when I think about it. 😝

Thanks for your input.
 
This problem seems to finally have been solved with the latest Sonoma beta.

/FWIW
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.