nproc.cpp 651 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. * Copyright (c) 2021, Peter Elliott <pelliott@ualberta.ca>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/JsonObject.h>
  7. #include <LibCore/File.h>
  8. #include <stdio.h>
  9. #include <unistd.h>
  10. int main()
  11. {
  12. if (pledge("stdio rpath", nullptr) < 0) {
  13. perror("pledge");
  14. return 1;
  15. }
  16. auto file = Core::File::construct("/proc/cpuinfo");
  17. if (!file->open(Core::OpenMode::ReadOnly)) {
  18. perror("Core::File::open()");
  19. return 1;
  20. }
  21. auto json = JsonValue::from_string({ file->read_all() });
  22. auto cpuinfo_array = json.value().as_array();
  23. outln("{}", cpuinfo_array.size());
  24. return 0;
  25. }