[go: nahoru, domu]

Skip to content

Commit

Permalink
launch multiple userspace programs
Browse files Browse the repository at this point in the history
  • Loading branch information
PauloMigAlmeida committed Dec 21, 2021
1 parent d6a2159 commit d20157d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/kernel/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void kmain(void) {
scheduler_init(init_proc);

/* test scheduler's ability to switch between tasks */
for (size_t i = 2; i <= 9; i++) {
for (size_t i = 2; i <= 99; i++) {
scheduler_add(create_process(0x1C000));
}

Expand Down
23 changes: 12 additions & 11 deletions src/user/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,29 @@
#include "libc/stdlib.h"

void umain(void) {
write("Hello from user space", 22);
/* greeting */
char msg[100];
memset(msg, '\0', sizeof(msg));

size_t counter = 0;
while (1) {
counter++;

if (counter % 100000000 == 0) {
/* get current time */
time_t now = time();
if (counter % 1000000 == 0) {
memset(msg, '\0', sizeof(msg));
memcpy(msg, "process ", 8);

/* get current process id */
pid_t curr_pid = getpid();
ltoa(curr_pid, msg + strlen(msg), 10);

/* print messge */
char msg[50];
memset(msg, '\0', sizeof(msg));
memcpy(msg, "process ", 8);
msg[8] = curr_pid + '0';
msg[9] = ' ';
memcpy(msg + strlen(msg), " unix time: ", 12);

ltoa(now, msg+10, 10);
/* get current time */
time_t now = time();
ltoa(now, msg + strlen(msg), 10);

/* print messge */
write(msg, strlen(msg) + 1);
}
}
Expand Down

0 comments on commit d20157d

Please sign in to comment.