nproc.cpp 605 B

1234567891011121314151617181920212223
  1. /*
  2. * Copyright (c) 2021, Peter Elliott <pelliott@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/JsonObject.h>
  7. #include <LibCore/File.h>
  8. #include <LibCore/System.h>
  9. #include <LibMain/Main.h>
  10. ErrorOr<int> serenity_main(Main::Arguments)
  11. {
  12. TRY(Core::System::pledge("stdio rpath", nullptr));
  13. auto file = TRY(Core::File::open("/proc/cpuinfo", Core::OpenMode::ReadOnly));
  14. auto buffer = file->read_all();
  15. auto json = TRY(JsonValue::from_string({ buffer }));
  16. auto const& cpuinfo_array = json.as_array();
  17. outln("{}", cpuinfo_array.size());
  18. return 0;
  19. }