While there is no single command in MATLAB that can obtain the process ID of the current session of MATLAB, to achieve this you can use the shell commands TASKLIST and PSLIST.
The MATLAB central files located in the following section, use the above shell commands to yield the current lists of tasks running on a machine :
You can download the above files, and use them in the following way from within MATLAB to obtain the process ID's of all the current MATLAB sessions:
1) Windows XP:
s = tasklist;
for i = 1:size(s,2)
cmp(i) = strcmp(s(1,i).name,'MATLAB.exe');
mpid = s(find(cmp==1)).pid
2) Windows (NT and higher) and LINUX:
s = pslist('MATLAB.EXE')
mpid = s.pid
Note that to use the PSLIST command in Windows, you need to download pslist.exe, which is a freeware.
Note that MathWorks does not control the content posted by visitors to MATLAB Central, and does not guarantee the accuracy or reliability of such content.