How about performing the system call asynchronously (https://uk.mathworks.com/help/parallel-computing/parallel.pool.parfeval.html) and polling from the main thread, something like this:
% Setup
tMax = 5; % Maximum time to wait for system call
pollDelay = 1; % Time between polls
timeOut = false;
% Run system call asynchronously
F = parfeval(@timeSystem,3,'iperfcmd');
tic
% Poll at regular intervals, break out if it finishes or exceeds time limit
while strcmp(F.State,'running') && ~timeOut
t = toc;
pause(pollDelay)
if t>tMax
timeOut = true; % This terminates the loop (alternatively use break)
end
end
if strcmp(F.State,'finished')
[status,cmdout,runTime]=fetchOutputs(F);
else
% Handle hanging system call here
cancel(F) % Cancelling the FutureEvent might terminate the system call?
end
function [status,cmdout,runTime] = timeSystem(command)
tStart = tic;
[status,cmdout] = system(command)
runTime = toc;
end
Hopefully that works for you. It's untested tested due to not having iperfcmd