1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 14:35:07 +00:00

Generate a basic /proc/summary file with some info about all tasks.

This commit is contained in:
Andreas Kling 2018-10-23 12:44:46 +02:00
parent ed2422d7af
commit 63e253bac9
5 changed files with 35 additions and 5 deletions

View file

@ -1,5 +1,5 @@
#include "ProcFileSystem.h"
#include <AK/StdLib.h>
#include "Task.h"
RetainPtr<ProcFileSystem> ProcFileSystem::create()
{
@ -18,7 +18,24 @@ bool ProcFileSystem::initialize()
{
SyntheticFileSystem::initialize();
addFile(createGeneratedFile("summary", [] {
return String("Process summary!").toByteBuffer();
cli();
auto tasks = Task::allTasks();
char* buffer;
auto stringImpl = StringImpl::createUninitialized(tasks.size() * 64, buffer);
memset(buffer, 0, stringImpl->length());
char* ptr = buffer;
ptr += ksprintf(ptr, "PID OWNER STATE NAME\n");
for (auto* task : tasks) {
ptr += ksprintf(ptr, "%w %w:%w %b %s\n",
task->pid(),
task->uid(),
task->gid(),
task->state(),
task->name().characters());
}
*ptr = '\0';
sti();
return ByteBuffer::copy((byte*)buffer, ptr - buffer);
}));
return true;
}