anchor.diff:    end.
   
   init_ps() ->
  -  [].
  +  {open_port({spawn,"/bin/sh"},[stream]),
  +   "ps -o pid,utime,time,vsz,rss,majflt,minflt -p "++os:getpid()++"\n"}.
  +
  +do_ps(Port,Cmd) ->
  +  case port_command(Port,Cmd) of
  +    true ->
  +      receive
  +        {Port,{data,Data}} ->
  +          case[string:tokens(L," ")||L<-string:tokens(Data,"\n")] of
  +            [["PID","UTIME","TIME","VSZ","RSS","MAJFLT","MINFLT"],
  +%%           ["1","0:00.20","0:00.30","2488932","12600","-","-"]]
  +             [_,Utime,Time,Vsz,Rss,MajFault,MinFault]] ->
  +              UtimeSec = timestr_to_sec(Utime),
  +              TimeSec =  timestr_to_sec(Time),              % system+user time
  +              [{beam_user,UtimeSec},
  +               {beam_kernel,TimeSec-UtimeSec},
  +               {beam_vsz,to_int(Vsz)*1024},                 % to bytes
  +               {beam_rss,to_int(Rss)},                      % in kB pages
  +               {beam_minflt,to_int(MinFault)},
  +               {beam_majflt,to_int(MajFault)}];
  +            _ ->
  +              []
  +          end
  +      end;
  +    false ->
  +      []
  +  end.
  +
  +%% "8:11.15"
  +timestr_to_sec(Str) ->
  +  case string:tokens(Str,":.") of
  +    [Min,Sec,CentiSec] -> 60*to_int(Min)+to_int(Sec)+to_int(CentiSec)/100;
  +    _ -> 0
  +  end.
  
positive.code: 
  os_info({linux,#fds{proc_stat=FDs,proc_self_stat=FDss}}) ->
    proc_stat(FDs)++proc_self_stat(FDss);
  os_info(_) ->
    [].
  
  proc_stat(FDs) ->
  %%user nice kernel idle iowait irq softirq steal
  
negative.code: %%   if OS is Linux 2.6 or greater;
  %%     - read from /proc/stat, /proc/meminfo (and /proc/net/dev ?)
  %%     - read from /proc/self/stat (and /proc/self/statm ?)
  %%   else if OS is darwin
  %%     - run the ps command in a port
  %%   else
  %%     - return an empty list
  