This repository has been archived by the owner on Aug 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
psom_heartbeat.m
69 lines (65 loc) · 2.69 KB
/
psom_heartbeat.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function [] = psom_heartbeat(file_heart,file_kill,pid)
% This function is internal to PSOM and not meant to be used directly.
%
% PSOM_HEARTBEAT(FILE_HEART,FILE_KILL,PID)
%
% FILE_HEART (string) the name of a .mat file. The following variables will be updated every 5s
% inside the .mat file:
% CURR_TIME (vector) the output of clock
% TELAPSED (scalar) the time (s) elapsed since the heartbeat was started.
% FILE_KILL (string) the name of a file. If this file is detected at any point in time
% the function will kill the process PID and exit.
% PID (scalar) a process ID.
%
% See licensing information in the code.
% Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008-2010.
% Departement d'informatique et de recherche operationnelle
% Centre de recherche de l'institut de Geriatrie de Montreal
% Universite de Montreal, 2011
% Maintainer : [email protected]
% See licensing information in the code.
% Keywords : pipeline
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the "Software"), to deal
% in the Software without restriction, including without limitation the rights
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
% copies of the Software, and to permit persons to whom the Software is
% furnished to do so, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be included in
% all copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
% THE SOFTWARE.
tic;
flag_beat = true;
path_heart = fileparts(file_kill);
while flag_beat
if exist('OCTAVE_VERSION','builtin')
[err,msg] = kill(pid,0); % use the kill octave command
else
[err,msg] = system(sprintf('kill -0 %i',pid)); % kill is not available, try a system call
end
flag_beat = err==0;
curr_time = clock;
try
save(file_heart,'curr_time');
end
if exist(file_kill,'file')||~psom_exist(path_heart)
if exist(file_kill,'file')
psom_clean(file_kill);
end
if exist('OCTAVE_VERSION','builtin')
kill(pid,9)
else
system(sprintf('kill -9 %i',pid));
end
exit
end
pause(5);
end