bmk_cores_linux.bmx 628 B

123456789101112131415161718192021222324252627282930
  1. SuperStrict
  2. Import Pub.stdc
  3. Extern
  4. ?bmxng
  5. Function popen:Byte Ptr(command:Byte Ptr, Mode:Byte Ptr)="FILE * popen(const char *, const char *)!"
  6. ?Not bmxng
  7. Function popen:Int(command:Byte Ptr, Mode:Byte Ptr)
  8. ?
  9. End Extern
  10. Function GetCoreCount:Int()
  11. Global count:Int
  12. If Not count Then
  13. Local buf:Byte[128]
  14. ?bmxng
  15. Local fp:Byte Ptr = popen("cat /proc/cpuinfo |grep -c '^processor'", "r")
  16. ?Not bmxng
  17. Local fp:Int = popen("cat /proc/cpuinfo |grep -c '^processor'", "r")
  18. ?
  19. fread_(buf, 1, 127, fp)
  20. fclose_(fp)
  21. count = String.FromCString(buf).ToInt()
  22. End If
  23. Return count
  24. End Function