Reputation: 31
I have added this function in proc.c file
int getNumProc(void)
{
struct proc *p;
int count = 0;
acquire(&ptable.lock);
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++)
{
if(p->state != UNUSED)
count++;
}
release(&ptable.lock);
return count;
}
I have made all the necessary modifications in the following files:
I also created a user program called totproc.c
to call this system call and added this user program in Makefile
at relevant places. When I type totproc
command in XV6 shell the command does print that there a 3 processes. But alongside the result, it also prints the following error :
pid 4 totproc: trap 14 err 5 on cpu 1 eip 0xffffffff addr 0xffffffff--kill proc
What could be wrong here? If you were to write a system call to find the number of processes, how would you write it?
Upvotes: 0
Views: 7237
Reputation: 31
Well , I figured out the problem. Turned out , the problem was not in my system call but in the user program totproc.c
that made the system call. My initial totproc.c
looked like this :
#include "types.h"
#include "stat.h"
#include "user.h"
int main()
{
printf(1 , "No. of Process: %d" , getNumProc());
return 0;
}
The properly working totproc.c
is like below :
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
int main()
{
printf(1 , "No. of Process: %d" , getNumProc());
exit();
}
Upvotes: 0
Reputation: 295
You seems to be in the right way but looks like you are missing something.
The error you are getting is being produced when an unexpected interrupt is received (in trap.c). Specifically, trap number 14 is T_PGFLT (according to trap.h). This means the MMU answered with a page fault interrupt when some address was being tried to access, in other words, you are probably having a memory overwrite or access violation somewhere.
Consider sharing you user space application code.
Upvotes: 0