ladybird/Userland/Utilities/nproc.cpp

24 lines
613 B
C++
Raw Normal View History

/*
* Copyright (c) 2021, Peter Elliott <pelliott@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/JsonObject.h>
#include <LibCore/File.h>
#include <LibCore/System.h>
2021-11-22 18:43:26 +00:00
#include <LibMain/Main.h>
2021-11-22 18:43:26 +00:00
ErrorOr<int> serenity_main(Main::Arguments)
{
TRY(Core::System::pledge("stdio rpath"));
auto file = TRY(Core::File::open("/sys/kernel/cpuinfo"sv, Core::File::OpenMode::Read));
auto buffer = TRY(file->read_until_eof());
2022-09-14 16:00:12 +00:00
auto json = TRY(JsonValue::from_string(buffer));
2021-11-22 18:43:26 +00:00
auto const& cpuinfo_array = json.as_array();
outln("{}", cpuinfo_array.size());
return 0;
}