Skip to content

Commit

Permalink
syscall processInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
OtnaelRochaSilva committed Dec 10, 2024
1 parent e4385b4 commit 325c58f
Showing 1 changed file with 42 additions and 24 deletions.
66 changes: 42 additions & 24 deletions syscall/processInfo.c
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/syscalls.h>
#include "processInfo.h"
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/syscalls.h>
#include "processInfo.h"

asmlinkage long sys_listProcessWaiting(){
/*
* i) lista os processos em espera
* ii) o processo superior ao parametro limit_age é finalizado
* iii) lista os processos finalizados
* *************************************/

//verifique se o estado dele é TASK_RUNNING (em execução), TASK_INTERRUPTIBLE (processo do usuário em sleep).
}

asmlinkage long sys_listProcessRun(){
/*
* i) lista os processos em execução
* ii) !avaliar viabilidade de preemptivamente retirar um processo da cpu
* */
}

asmlinkage long sys_listProcessInfo(long pid, const char __user *buf, int size) {
struct task_struct *proces;
unsigned char kbuf[256];
int bufsz;
int ret;
asmlinkage long sys_listProcessInfo(long pid, const char __user *buf, int size) {
struct task_struct *proces;
unsigned char kbuf[256];
int bufsz;
int ret;

/* Find the process */
for_each_process(proces) {
if( (long)task_pid_nr(proces) == pid){
/* Print the process info to the buffer */
snprintf(kbuf, sizeof(kbuf), "Process: %s\n PID_Number: %ld\n Process State: %ld\n Priority: %ld\n RT_Priority: %ld\n Static Priority: %ld\n Normal Priority: %ld\n",
proces->comm,
(long)task_pid_nr(proces),
(long)proces->__state,
(long)proces->prio,
(long)proces->rt_priority,
(long)proces->static_prio, (long)proces->normal_prio);
/* Find the process */
for_each_process(proces) {
if( (long)task_pid_nr(proces) == pid){
/* Print the process info to the buffer */
snprintf(kbuf, sizeof(kbuf), "Process: %s\n PID_Number: %ld\n Process State: %ld\n Priority: %ld\n RT_Priority: %ld\n Static Priority: %ld\n Normal Priority: %ld\n",
proces->comm,
(long)task_pid_nr(proces),
(long)proces->__state,
(long)proces->prio,
(long)proces->rt_priority,
(long)proces->static_prio,
(long)proces->normal_prio);
bufsz = strlen(kbuf)+1;

/* User buffer is too small */
Expand All @@ -32,9 +50,9 @@
ret = copy_to_user((void*)buf, (void*)kbuf, bufsz);

return bufsz - ret;
}
}

/* Process not found */
return -2;
}

/* Process not found */
return -2;
}

0 comments on commit 325c58f

Please sign in to comment.