Basic shell

This commit is contained in:
2024-04-07 22:59:01 +02:00
parent 8ae69b4bc5
commit b56a314bdd
8 changed files with 67 additions and 65 deletions

View File

@@ -2,48 +2,48 @@
#include "stdio.h"
#include "stdlib.h"
#include <sys/fcntl.h>
#include <dirent.h>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/unistd.h>
#include <unistd.h>
void ls() {
DIR *rfd = opendir("/");
struct dirent *cur = readdir(rfd);
while (cur) {
printf("%s\n", cur->d_name);
cur = readdir(rfd);
}
closedir(rfd);
}
int main() {
malloc(100);
malloc(100);
malloc(100);
malloc(100);
printf("Who are you?\n");
char *line = NULL;
size_t len = 0;
// __getline(&line, &len, stdin);
{
uint64_t test123 = open("/test123", O_CREAT | O_RDWR);
const char *teststr = "test str";
write(test123, teststr, 9);
close(test123);
printf("hi %s\n", line);
// sputchar('h');
// sputchar('i');
// sputchar('\n');
uint64_t test123 = open("/test123", O_CREAT | O_RDWR);
const char *teststr = "test str";
write(test123, teststr, 9);
close(test123);
test123 = open("/test123", O_RDONLY);
char buf[123];
read(test123, buf, 9);
printf("\n %s \n", buf);
usleep(100);
execve("/hello2", 0, 0);
test123 = open("/test123", O_RDONLY);
char buf[123];
read(test123, buf, 9);
close(test123);
printf("\n %s \n", buf);
}
while (1) {
printf("\n");
char c;
scanf(" %c", &c);
if (c == 'm') print_mem();
if (c == 't') print_tasks();
if (c == 'h') execve("/hello2", 0, 0);
printf("%c", c);
printf("\n> ");
char line[30];
scanf(" %24[^\n]", line);
if (strcmp(line, "ls") == 0) {
ls();
} else if (strcmp(line, "mem") == 0) {
print_mem();
} else if (strcmp(line, "tasks") == 0) {
print_tasks();
} else {
execve(line, 0, 0);
}
}
}