From 5f8ba396a36b15ffb59b42146af7d70f3480f76d Mon Sep 17 00:00:00 2001 From: DiegoArandaUAI Date: Sun, 11 Sep 2022 16:43:48 -0300 Subject: [PATCH 1/2] tarea1 --- Makefile | 2 ++ cuenta.c | 9 +++++++++ defs.h | 1 + proc.c | 18 ++++++++++++++++++ proc.h | 1 + syscall.c | 3 +++ syscall.h | 1 + sysproc.c | 7 +++++++ user.h | 1 + usys.S | 1 + 10 files changed, 44 insertions(+) create mode 100644 cuenta.c diff --git a/Makefile b/Makefile index 09d790cf63..5b5eac1d1e 100644 --- a/Makefile +++ b/Makefile @@ -181,6 +181,7 @@ UPROGS=\ _usertests\ _wc\ _zombie\ + _cuenta\ fs.img: mkfs README $(UPROGS) ./mkfs fs.img README $(UPROGS) @@ -250,6 +251,7 @@ qemu-nox-gdb: fs.img xv6.img .gdbinit EXTRA=\ mkfs.c ulib.c user.h cat.c echo.c forktest.c grep.c kill.c\ ln.c ls.c mkdir.c rm.c stressfs.c usertests.c wc.c zombie.c\ + cuenta.c\ printf.c umalloc.c\ README dot-bochsrc *.pl toc.* runoff runoff1 runoff.list\ .gdbinit.tmpl gdbutil\ diff --git a/cuenta.c b/cuenta.c new file mode 100644 index 0000000000..503e561902 --- /dev/null +++ b/cuenta.c @@ -0,0 +1,9 @@ +#include "types.h" +#include "stat.h" +#include "user.h" +#include "fcntl.h" + +int main(void) { +printf(1 , "La cantidad de procesos en ejecucion en la CPU es %d\n", getprocs()); +exit(); +} diff --git a/defs.h b/defs.h index 82fb982837..23cc6d40c8 100644 --- a/defs.h +++ b/defs.h @@ -120,6 +120,7 @@ void userinit(void); int wait(void); void wakeup(void*); void yield(void); +int countproc(void); // swtch.S void swtch(struct context**, struct context*); diff --git a/proc.c b/proc.c index 806b1b184b..ee3e535bb9 100644 --- a/proc.c +++ b/proc.c @@ -532,3 +532,21 @@ procdump(void) cprintf("\n"); } } + +int +countproc(void) +{ + struct proc *p; + int counter = 0; + acquire(&ptable.lock); + + for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ + if(p->state != UNUSED){ + counter++; + } + } + + release(&ptable.lock); + + return counter; +} \ No newline at end of file diff --git a/proc.h b/proc.h index 1647114179..421dd72d22 100644 --- a/proc.h +++ b/proc.h @@ -49,6 +49,7 @@ struct proc { struct file *ofile[NOFILE]; // Open files struct inode *cwd; // Current directory char name[16]; // Process name (debugging) + int tickets; }; // Process memory is laid out contiguously, low addresses first: diff --git a/syscall.c b/syscall.c index ee85261602..854d12d58b 100644 --- a/syscall.c +++ b/syscall.c @@ -103,6 +103,7 @@ extern int sys_unlink(void); extern int sys_wait(void); extern int sys_write(void); extern int sys_uptime(void); +extern int sys_getprocs(void); static int (*syscalls[])(void) = { [SYS_fork] sys_fork, @@ -126,6 +127,7 @@ static int (*syscalls[])(void) = { [SYS_link] sys_link, [SYS_mkdir] sys_mkdir, [SYS_close] sys_close, +[SYS_getprocs] sys_getprocs, }; void @@ -143,3 +145,4 @@ syscall(void) curproc->tf->eax = -1; } } + diff --git a/syscall.h b/syscall.h index bc5f35651c..751fe31e5b 100644 --- a/syscall.h +++ b/syscall.h @@ -20,3 +20,4 @@ #define SYS_link 19 #define SYS_mkdir 20 #define SYS_close 21 +#define SYS_getprocs 22 diff --git a/sysproc.c b/sysproc.c index 0686d295b6..7a3d3486f9 100644 --- a/sysproc.c +++ b/sysproc.c @@ -42,6 +42,12 @@ sys_getpid(void) return myproc()->pid; } +int +sys_getprocs(void) +{ + return countproc(); +} + int sys_sbrk(void) { @@ -89,3 +95,4 @@ sys_uptime(void) release(&tickslock); return xticks; } + diff --git a/user.h b/user.h index 4f99c52ba6..77f7b7e0f8 100644 --- a/user.h +++ b/user.h @@ -23,6 +23,7 @@ int getpid(void); char* sbrk(int); int sleep(int); int uptime(void); +int getprocs(void); // ulib.c int stat(const char*, struct stat*); diff --git a/usys.S b/usys.S index 8bfd8a1bc4..b38d0c0d51 100644 --- a/usys.S +++ b/usys.S @@ -29,3 +29,4 @@ SYSCALL(getpid) SYSCALL(sbrk) SYSCALL(sleep) SYSCALL(uptime) +SYSCALL(getprocs) \ No newline at end of file From 669a760ff04395cfb401c3c9451f81bb12cdce8d Mon Sep 17 00:00:00 2001 From: DiegoArandaUAI Date: Sun, 11 Sep 2022 16:51:15 -0300 Subject: [PATCH 2/2] borre los tickets de la tarea2 en la tarea 1 --- proc.h | 1 - 1 file changed, 1 deletion(-) diff --git a/proc.h b/proc.h index 421dd72d22..1647114179 100644 --- a/proc.h +++ b/proc.h @@ -49,7 +49,6 @@ struct proc { struct file *ofile[NOFILE]; // Open files struct inode *cwd; // Current directory char name[16]; // Process name (debugging) - int tickets; }; // Process memory is laid out contiguously, low addresses first: