1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 21:57:44 +00:00

LibCore: Report error condition when reading process statistics failed

This commit is contained in:
Tom 2021-01-01 20:58:47 -07:00 committed by Andreas Kling
parent 754bf22da7
commit cf89180c35
12 changed files with 94 additions and 74 deletions

View file

@ -41,8 +41,10 @@ static void print_usage_and_exit()
static int kill_all(const String& process_name, const unsigned signum)
{
auto processes = Core::ProcessStatisticsReader().get_all();
if (!processes.has_value())
return 1;
for (auto& it : processes) {
for (auto& it : processes.value()) {
if (it.value.name == process_name) {
int ret = kill(it.value.pid, signum);
if (ret < 0)

View file

@ -166,9 +166,11 @@ int main(int argc, char* argv[])
}
printf("%-28s %4s %4s %-10s %4s %s\n", "COMMAND", "PID", "PGID", "USER", "FD", "NAME");
auto processes = Core::ProcessStatisticsReader::get_all();
if (!processes.has_value())
return 1;
if (arg_pid == -1) {
auto processes = Core::ProcessStatisticsReader::get_all();
for (auto process : processes) {
for (auto process : processes.value()) {
if (process.key == 0)
continue;
auto open_files = get_open_files_by_pid(process.key);
@ -187,14 +189,13 @@ int main(int argc, char* argv[])
}
}
} else {
auto processes = Core::ProcessStatisticsReader::get_all();
auto open_files = get_open_files_by_pid(arg_pid);
if (open_files.is_empty())
return 0;
for (auto file : open_files) {
display_entry(file, processes.get(arg_pid).value());
display_entry(file, processes.value().get(arg_pid).value());
}
}

View file

@ -40,8 +40,10 @@ static int pid_of(const String& process_name, bool single_shot, bool omit_pid, p
bool displayed_at_least_one = false;
auto processes = Core::ProcessStatisticsReader().get_all();
if (!processes.has_value())
return 1;
for (auto& it : processes) {
for (auto& it : processes.value()) {
if (it.value.name == process_name) {
if (!omit_pid || it.value.pid != pid) {
printf(" %d" + (displayed_at_least_one ? 0 : 1), it.value.pid);

View file

@ -120,8 +120,10 @@ int main(int argc, char** argv)
printf("\n");
auto all_processes = Core::ProcessStatisticsReader::get_all();
if (!all_processes.has_value())
return 1;
for (const auto& it : all_processes) {
for (const auto& it : all_processes.value()) {
const auto& proc = it.value;
auto tty = proc.tty;

View file

@ -92,11 +92,12 @@ struct Snapshot {
static Snapshot get_snapshot()
{
Snapshot snapshot;
auto all_processes = Core::ProcessStatisticsReader::get_all();
if (!all_processes.has_value())
return {};
for (auto& it : all_processes) {
Snapshot snapshot;
for (auto& it : all_processes.value()) {
auto& stats = it.value;
for (auto& thread : stats.threads) {
snapshot.sum_times_scheduled += thread.times_scheduled;

View file

@ -77,6 +77,10 @@ int main()
}
auto process_statistics = Core::ProcessStatisticsReader::get_all();
if (!process_statistics.has_value()) {
warnln("Error: Could not get process statistics");
return 1;
}
auto now = time(nullptr);
@ -110,7 +114,7 @@ int main()
String what = "n/a";
for (auto& it : process_statistics) {
for (auto& it : process_statistics.value()) {
if (it.value.tty == tty && it.value.pid == it.value.pgid)
what = it.value.name;
}