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

@ -45,7 +45,7 @@ public:
InlineLinkedList() { }
bool isEmpty() const { return !m_head; }
size_t size() const;
size_t sizeSlow() const;
void clear();
T* head() const { return m_head; }
@ -72,7 +72,7 @@ private:
T* m_tail { nullptr };
};
template<typename T> inline size_t InlineLinkedList<T>::size() const
template<typename T> inline size_t InlineLinkedList<T>::sizeSlow() const
{
size_t size = 0;
for (T* node = m_head; node; node = node->next())

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;
}

View file

@ -95,6 +95,15 @@ void Task::allocateLDT()
m_tss.ldt = newLDTSelector;
}
Vector<Task*> Task::allTasks()
{
Vector<Task*> tasks;
tasks.ensureCapacity(s_tasks->sizeSlow());
for (auto* task = s_tasks->head(); task; task = task->next())
tasks.append(task);
return tasks;
}
Task::Region* Task::allocateRegion(size_t size, String&& name)
{
// FIXME: This needs sanity checks. What if this overlaps existing regions?

View file

@ -19,6 +19,8 @@ public:
static Task* create(const String& path, uid_t, gid_t);
Task(String&& name, uid_t, gid_t);
static Vector<Task*> allTasks();
#ifdef TASK_SANITY_CHECKS
static void checkSanity(const char* msg = nullptr);
#else
@ -58,6 +60,8 @@ public:
TSS32& tss() { return m_tss; }
State state() const { return m_state; }
IPC::Handle handle() const { return m_handle; }
uid_t uid() const { return m_uid; }
uid_t gid() const { return m_gid; }
const FarPtr& farPtr() const { return m_farPtr; }

View file

@ -138,7 +138,7 @@ static void init_stage2()
vfs->mount(procfs.copyRef(), "/proc");
{
auto motdFile = vfs->open("/motd.txt");
auto motdFile = vfs->open("/proc/summary");
ASSERT(motdFile);
auto motdData = motdFile->readEntireFile();