How can I get the PID of the current MATLAB session?
41 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 8 Déc 2011
Modifié(e) : MathWorks Support Team
le 23 Fév 2024
I want to find out the PID (process ID) of the current MATLAB session programmatically on Windows and Unix machines.
Réponse acceptée
MathWorks Support Team
le 23 Fév 2024
Modifié(e) : MathWorks Support Team
le 23 Fév 2024
In newer versions of MATLAB, you can obtain the PID of a MATLAB process with the MATLAB command:
>> feature('getpid')
Please note that the use of the "feature" function is undocumented, meaning that it can be removed or changed at any time.
Another option would be to use the basic system commands. To get started, here are the commands to get all processes with "matlab" in their name:
% For Windows
>> [~,procs] = system('tasklist | findstr -i "MATLAB.exe"')
% For Unix
>> [~,procs] = system("ps aux | grep matlab | grep your_username")
.
NOTE: If the goal is to manage multiple MATLAB sessions for computation, we recommend using the "batch" function in the Parallel Computing Toolbox. This enables the user to run scripts and functions in the background, and it automatically returns a "parallel.Job" object that enables access to the state of the running script and the methods to control the running script.
1 commentaire
Oliver Woodford
le 23 Déc 2015
I believe this will only work if there is only one instance of MATLAB running. It isn't useful if you are running multiple instances, and want the process ID of the particular instance, because it cannot distinguish between them.
Plus de réponses (1)
Darin McCoy
le 21 Fév 2014
Butttt...later versions of matlab allow you to do it with this command
feature('getpid')
0 commentaires
Voir également
Catégories
En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!