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:
parent
ed2422d7af
commit
63e253bac9
5 changed files with 35 additions and 5 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue