0

in MATLAb language , to get the pid of a running process , I did :

pid = getpidof('processName.exe')

it returns []

whereas the process is running on my windows ?

it is the correct syntax ?

4

1 回答 1

4

I don't know what the function getpidof is or does - it doesn't appear to be a standard Matlab function (2012b). Here's a quick hack to find the pid of a running process -

>> [response, tasks] = system('tasklist | find "explorer.exe"');
>> splits = regexp(tasks, ' *', 'split');
>> pid = str2double(splits{2});

You can wrap that up into a function if you need to. Be aware that it is quite slow.

Edit - here's the function

function pid = getpidof(task)
# Get the process id of a task by name.

    [response, tasks] = system(sprintf('tasklist | find "%s"', task));

    splits = regexp(tasks, ' *', 'split');

    pid = str2double(splits{2});

end
于 2013-10-01T09:42:29.520 回答