Matlab and 'sandbox' process Peak CPU Usage in macOS Big Sur

Matlab version: 9.10.0.1684407 (R2021a) Update 3'
System Version: Big Sur 11.4 (20F71)
MacBook Pro: (13-inch, 2020, Four Thunderbolt 3 ports)
Processor: 2 GHz Quad-Core Intel Core i5
Memory: 16 GB 3733 MHz LPDDR4X
Graphics card: Intel Iris Plus Graphics 1536 MB
Problem:
In the image bellow I pressed command+return to run the code and the sandboxed process started to peak. This happens all the time while using matlab. Sometimes even when just typing in in the code editor. I even tried closing all other applications in the system and run just Matlab, the problem persisted.
From time to time the sandboxd process peaks CPU usage and the entire Matlab becomes laggy, impossible to use. It is a recurrent problem. I tried installing 2020b version, but same thing happened. I'm not using Magnet or other window snaping tool.
I've sent a feedback to Mathworks under this identifier when it happened to froze once, forcing me to quit the application: Help troubleshooting recent MATLAB crash: 04938298 ref:_00Di0Ha1u._5003q1PuOu8:ref

 Accepted Answer

This is a known issue in Big Sur 11.4 for M1.
I notice that you are not using M1; it is plausible that the same underlying problem is responsible (whatever that problem is.)
People have been reporting that R2021a Update 3 helps; I see you are already using that.
There is a bug report that indicates that some people may need to start MATLAB from Terminal to prevent crashes.

7 Comments

Indeed, If I run it from the terminal then it does not give me the lagging or crashing. As a workaround I've created an .Application in Apple's Automator (shipped with your MacOS installation) to run matlab usiing terminal from the instalation folder. I've copied the icon from the Matlab folder and then docked the application. So everytime I click in the Docked app it opens a terminal and imediatilly starts to run Matlab.
Steps:
  • Open Automator
  • Select 'Application' as the type of document;
  • Then, scroll down to find the 'Run Shell Script' automation;
  • Drag this automation to the right to add to the workflow;
  • Then inside the black box write the following (adapting to your instalation path):
cd /Applications/MATLAB_R2021a.app/bin/
open matlab
  • Save wihth the name you want in the folder you want (I chose MATLAB inside Documents);
  • Now, go in the Matlab instalation folder and search for 'MATLAB.icns' (It is the icon image for Matlab);
  • Copy this file to the folder you have save the application;
  • Open the 'Get Info' of the Application created in the Automator;
  • Drag and drop the Icon in the 'Get Info' window (closer to the automator icon at the top left), it will change the Icon of the application, and it will look like matlab's icon;
  • Finally drag the application to your dock;
  • Done, now everytime you click on the dock application, it will open a terminal and run matlab for you.
So far, no more crashing, as soon as developers fix this issue we can go back to normal running! I've attached the automator file and matlab icon to this post.
Please, keep us posted when it is fixed!
I am currently working with r2021, Mac Os Big Sur 11.4, MacBook Pro (15-inch, 2017), Processor: 2,8 GHz Quad-Core Intel Core i7, and i had exactly the same problem. an update 3 did not help. Then I created an application with the Automator and since then Matlab has, been running flawlessly. Many Thanks. Fernando
Running it from the terminal indeed works! But why? How is it that this way sandboxd is bypassed? Anyway, thank you so much, I will be running it from the terminal until a permanent solution exists : )
I'm on Big Sur 11.5 using r2021a Update 4, and experiencing the same issue. I don't think I have an M1 chip though (mid-2015 MacBook Pro).
I am having the same problem but starting from the terminal does not solve it. (Using Mac Big Sur with Intel chip, R2021b and R2022a prerelease)
Walter, any update on this issue? I'm using 11.7.1, matlab R2022b, Mac Pro with intel chip. Hoping to not go the route of Tim Lueth described below, but need a solution, thanks

Sign in to comment.

More Answers (4)

Kill this process was the only solution which worked for me. I'm having to do that roughly every 30min.
Tim Lueth
Tim Lueth on 29 Dec 2021
Edited: Tim Lueth on 29 Dec 2021
The problem occurs frequently, even in 11.6.2 (Big Sur) with 2021b. I agree with Raphaël Nussbaumer that stopping the spindump task fixes the problem. For me, it occurs when the editor window is clicked from the command window or a file is opened with a double click, on OSX (MacBook Pro (13", 2020, 2.3 GHz quad-core Intel Core i7, 32 GB 3733 MHz LPDDR4X)
I'm not sure if what just worked for me will work for everyone -- it sounds like there could possibly be several closely-related variations on the same issue. But my 2021b was hanging on startup similar to what others were getting. I tried launching from the command line without the desktop running ( /Applications/MATLAB_R2021b.app/bin/matlab -nodesktop ) and then running the desktop command from within the terminal. When I did that, I got an error message about my desktop layout configuration XML file being corrupted, and that MATLAB was going to use the default configuration. I went ahead and re-positioned my window and panes, and then exited MATLAB and restarted the usual (non-command-line) way, and it started up just fine (and it appeared to have successfully saved my desktop layout). Again, not sure if others are having the same issue for the same reason, but perhaps this will fix some cases?

1 Comment

I have tried this. Unfortunately, it did not help to fix the spindump/sandbox problem on 2021b and OSX10.16.

Sign in to comment.

Since I use Matlab on an Apple Mac every week in lectures, I was tired of having this problem several times each week in front of hundreds of students! There is no warning but Matlab slows down and slows down and finally "stands" without error message. Especially for functions or scripts that run for several seconds or minutes, detection is very difficult, time wasting and switching to the terminal program and entering the superuser password is unprofessional.
The solution works in four steps:
1st: Find the PID number of the sandbox process and the spindump process
[a,b]=system(sprintf('ps auxww')); c=strsplit(b,char(10))'; d=c(contains(c,'/usr/sbin/spindump','IgnoreCase',true)), e=split(d);
if ~isempty(e); PID1=e{2}; else PID1=[]; end;
% [a,b]=system(sprintf('ps auxww')); c=strsplit(b,char(10))'; d=c(contains(c,'/usr/libexec/sandboxd','IgnoreCase',true)), e=split(d);
% if ~isempty(e); PID2=e{2}; else PID2=[]; end;
2nd: Kill the process as super user using your private sudo password in the command line. YOU HAVE TO EXCHANGE <yoursudopassword> by your own password without the <> chars.
if ~isempty(PID1); system(sprintf('echo <yoursudopassword> | sudo -S kill -9 %s',PID1)); end;
3rd: Write a loop that checks every second whether the process exists (and uses more that 1% of CPU time)
function spindumpkill
while true
pause(1);
[a,b]=system(sprintf('ps auxww')); c=strsplit(b,char(10))'; d=c(contains(c,'/usr/sbin/spindump','IgnoreCase',true)), e=split(d);
if ~isempty(e); PID1=e{2}; else PID1=[]; end;
if ~isempty(PID1); system(sprintf('echo <yoursudopassword> | sudo -S kill -9 %s',PID1)); end;
end
4th: Start this function as batch process in the background (using the parallel box) or create an OSX-App for that.
batch spindumpkill

9 Comments

Hello, I'm undergrad EE student from Indonesia currently studying in Malaysia.
I'd like to ask, I think I have the same problem, and that I'm using macOS Monterey 12.6.3 and MATLAB r2022b. My problem occurs and MATLAB freezes when I tried closing a figure window by pressing the "x" button, but for this when I expand pressing the green button then close with the same "x" button it seems ok. However, the same problem also occurs when I use scope within simulink when I simulate a simscape electrical model, so far there's no particular pattern that I could find regarding why this happens, it seems just after several minutes (or seconds in some instance) after running the simulation it freezes, I do not know if other model and using the scope will freeze as well.
I previously used r2021b, but the .slx file model provided by our lecturer cannot open it since it is made using newer version of r2022a. Please if you would be so kind as to help assist a bit on your provided solution -- does it mean I have to make an app with the code you provided? I asked chatGPT, it seems your code is a MATLAB code so does it mean in that case I have to put it in script and run everytime I run MATLAB? please elaborate more.
Also, I have not updated to macOS 13.x Ventura, but if it would fix then I would upgrade. Downgrading macOS is kinda not an option, since I will need to erase everything, and I don't have time for another problems with a different complexity, and the assignment due is kinda in 2 days. Using r2022a might be an option, if it makes it more stable, I have been installing MATLAB dozens time for the past few days.
Your help will be appreciative, after this I think it's either I will not macOS as the main OS I use next laptop I'd buy, or maybe just use Open Source programs and that I'll be finishing my degree soon inshallah anyway, and I would lose access to MATLAB/Mathworks anyway.
Hey,
It's been a while now, but since I've updated my system to MacOS to Ventura 13.1 and Matlab R2022_b I haven't seen this problem anymore.
@Tim Lueth, can you really explain step 1 through 4, I do not understand most of it such as "..batch process in the backgroud..", I have already installed the Parallel Computing Toolbox.
@Joao Nizer I tried using your solution of making .app in the automator, and wrote the line below:
cd /Applications/MATLAB_R2022b.app/bin
open matlab
And I deleted "cat" in the Run Shell Script, while the Shell is /bin/bash, and Pass input is: to stdin
macOS Monterey 12.6.3
r2022b
it did not work, still froze when I use scope in Simscape Electrical Simulink
if @Tim Lueth or you @Joao Nizer, or anyone could explain step 1-4 by @Tim Lueth solution. Please let me know, thank you
"4th: Start this function as batch process in the background (using the parallel box) or create an OSX-App for that."
That includes several possibilities:
@Walter Roberson, so here is what I did. And I also have Parallel Computing Toolbox
I copied the code into the function:
function spindumpkill
[a,b]=system(sprintf('ps auxww')); c=strsplit(b,char(10))'; d=c(contains(c,'/usr/sbin/spindump','IgnoreCase',true)), e=split(d);
if ~isempty(e); PID1=e{2}; else PID1=[]; end;
if ~isempty(PID1); system(sprintf('echo <my password> | sudo -S kill -9 %s',PID1)); end;
while true
pause(1);
[a,b]=system(sprintf('ps auxww')); c=strsplit(b,char(10))'; d=c(contains(c,'/usr/sbin/spindump','IgnoreCase',true)), e=split(d);
if ~isempty(e); PID1=e{2}; else PID1=[]; end;
if ~isempty(PID1); system(sprintf('echo <my password> | sudo -S kill -9 %s',PID1)); end;
end
and I saved the file in .m format in the path, with the same name as the function:
/Users/<computer username>/Documents/MATLAB/spindumpkill.m
Then I run, in the command window:
I don't know why but the "ID kept increasing" each time I run
I also attached the .m file, however it's renamed "spindumpkill_copy.m" but I run the "spindumpkill.m" one.
It's not fixed yet, when I run Simscape Electrical Simulink then I double-click the "scope", it still freezes after couple of seconds.
I also tried putting the 1st and 2nd step in different line and put it under the "while" loop like this:
function spindumpkill
while true
[a,b]=system(sprintf('ps auxww')); c=strsplit(b,char(10))'; d=c(contains(c,'/usr/sbin/spindump','IgnoreCase',true)), e=split(d);
if ~isempty(e); PID1=e{2}; else PID1=[]; end;
if ~isempty(PID1); system(sprintf('echo <my password> | sudo -S kill -9 %s',PID1)); end;
pause(1);
[a,b]=system(sprintf('ps auxww')); c=strsplit(b,char(10))'; d=c(contains(c,'/usr/sbin/spindump','IgnoreCase',true)), e=split(d);
if ~isempty(e); PID1=e{2}; else PID1=[]; end;
if ~isempty(PID1); system(sprintf('echo <my password> | sudo -S kill -9 %s',PID1)); end;
end
It still freezes.
Should I just upgrade to macOS 13.x Ventura, but I'm afraid it won't be reversible, if I needed to revert back to Monterey.
The ID number for batch() is tracking which batch session request this is. Because batch are designed to have the results stay around until collected, the ID number increments for each new batch() request and ID numbers are not reused until you go in and remove the appropriate file that the number is being recorded into. It will not normally reset between sessions, as it is expected that you might drop out of MATLAB and return later to find out how the batch sessions are going.

Sign in to comment.

Categories

Products

Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!