github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/lang/expressions/testcode/testcode_progress.mx (about)

     1  function progress {
     2      # Pulls the read progress of a Linux pid via /proc/$pid/fdinfo (only runs on Linux)
     3  
     4      if { ${os}=="linux" } then {
     5          #params -> [ 1 ] -> set pid
     6          $1 -> set pid
     7          
     8          g <!null> /proc/$pid/fd/* -> regexp <!null> (f,/proc/[0-9]000/fd/([0-9]+)) -> foreach <!null> fd {
     9              trypipe <!null> {
    10                  open /proc/$pid/fdinfo/$fd -> cast yaml -> [ pos ] -> set pos
    11                  readlink: /proc/$pid/fd/$fd -> set file
    12                  du -b $file -> [ :0 ] -> set int size
    13                  if { = size > 0 } then {
    14                      = ($pos/$size)*100 -> set int percent
    15                      out "$percent% ($pos/$size) $file"
    16                  }
    17              }
    18          }
    19      }
    20  }