mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 03:37:35 +00:00
Start adding a basic /proc filesystem and a "ps" utility.
This commit is contained in:
parent
98f76f0153
commit
ed2422d7af
13 changed files with 139 additions and 23 deletions
1
Userland/.gitignore
vendored
1
Userland/.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
id
|
||||
sh
|
||||
ps
|
||||
*.o
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
OBJS = \
|
||||
id.o \
|
||||
sh.o
|
||||
sh.o \
|
||||
ps.o
|
||||
|
||||
APPS = \
|
||||
id \
|
||||
sh
|
||||
sh \
|
||||
ps
|
||||
|
||||
ARCH_FLAGS =
|
||||
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib
|
||||
|
@ -30,6 +32,9 @@ id: id.o
|
|||
sh: sh.o
|
||||
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||
|
||||
ps: ps.o
|
||||
$(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a
|
||||
|
||||
.cpp.o:
|
||||
@echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $<
|
||||
|
||||
|
|
25
Userland/ps.cpp
Normal file
25
Userland/ps.cpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include <LibC/stdio.h>
|
||||
#include <LibC/unistd.h>
|
||||
|
||||
int main(int c, char** v)
|
||||
{
|
||||
int fd = open("/proc/summary");
|
||||
if (fd == -1) {
|
||||
printf("failed to open /proc/summary :(\n");
|
||||
return 1;
|
||||
}
|
||||
for (;;) {
|
||||
char buf[16];
|
||||
ssize_t nread = read(fd, buf, sizeof(buf));
|
||||
if (nread == 0)
|
||||
break;
|
||||
if (nread < 0) {
|
||||
printf("failed to read :(\n");
|
||||
return 2;
|
||||
}
|
||||
for (ssize_t i = 0; i < nread; ++i) {
|
||||
putchar(buf[i]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue