Bug Fixing and add a new feature
This commit is contained in:
@@ -1,16 +1,7 @@
|
||||
--PID'S RECORDING SESSION--
|
||||
|
||||
PID NOME
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
MODE:
|
||||
|
||||
PID PRIO NAME
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "sys/types.h"
|
||||
|
||||
void writeFeedback(pid_t pid, char name[]);
|
||||
void writeFeedback(pid_t pid, char name[], pid_t padre, int mode, int prio);
|
||||
|
||||
/// @brief Initialize the scheduler feedback system.
|
||||
/// @return 1 on success, 0 on failure.
|
||||
|
||||
@@ -64,7 +64,7 @@ static inline task_struct *__scheduler_rr(runqueue_t *runqueue, bool_t skip_peri
|
||||
// We have our next entry.
|
||||
|
||||
//function to track the scheduler algorithm
|
||||
writeFeedback(entry->pid, entry->name);
|
||||
writeFeedback(entry->pid, entry->name, entry->parent->pid, 1, (entry->se).prio);
|
||||
|
||||
return entry;
|
||||
}
|
||||
@@ -127,6 +127,10 @@ static inline task_struct *__scheduler_priority(runqueue_t *runqueue, bool_t ski
|
||||
next = entry; // scambio il prossimo processo con quello a priorità piu bassa trovato
|
||||
}
|
||||
}
|
||||
|
||||
//function to track the scheduler algorithm
|
||||
writeFeedback(next->pid, next->name, next->parent->pid, 2, (next->se).prio);
|
||||
|
||||
return next;
|
||||
#else
|
||||
return __scheduler_rr(runqueue, skip_periodic);
|
||||
@@ -173,6 +177,9 @@ static inline task_struct *__scheduler_cfs(runqueue_t *runqueue, bool_t skip_per
|
||||
next = entry; // scambio il prossimo processo con quello a priorità piu bassa trovato
|
||||
}
|
||||
}
|
||||
//function to track the scheduler algorithm
|
||||
writeFeedback(next->pid, next->name, next->parent->pid, 3, (next->se).prio);
|
||||
|
||||
return next;
|
||||
#else
|
||||
return __scheduler_rr(runqueue, skip_periodic);
|
||||
|
||||
@@ -35,9 +35,13 @@ Istruzioni relative ai parametri della funzione start (che sono work in progress
|
||||
#define MAX_STORAGE 10
|
||||
int count = 0;
|
||||
pid_t PID_BUFFER[MAX_STORAGE] = { 0 };
|
||||
int PID_PRIO[MAX_STORAGE] = { 0 };
|
||||
char PID_NAME[MAX_STORAGE][MAX_SIZE_NAME];
|
||||
pid_t oldPid = -1;
|
||||
ssize_t offset;
|
||||
int err = 1;
|
||||
int countChar(char[]);
|
||||
void wipe();
|
||||
|
||||
/*
|
||||
PID 1 --> INIT
|
||||
@@ -47,24 +51,26 @@ int countChar(char[]);
|
||||
/*
|
||||
Funzione che viene chiamata da scheduler_algorithm dopo aver scelto il prossimo processo da eseguire
|
||||
*/
|
||||
void writeFeedback(pid_t pid, char name[])
|
||||
void writeFeedback(pid_t pid, char name[], pid_t padre, int mode, int prio)
|
||||
{
|
||||
|
||||
int brake = 0;
|
||||
char start[] = "start";
|
||||
int brake = 0;
|
||||
|
||||
|
||||
//analizzo se nome del PID passato come argomento corrisponde al comando START
|
||||
for (int i = 0; i < countChar(name) && brake == 0; i++) {
|
||||
if ((start[i] != name[i]) || oldPid==pid ) { //brake a 0 anche se viene rilevata una start che non è stata lanciata da terminale ma è in esecuzione de un po
|
||||
|
||||
if ((start[i] != name[i]) || oldPid==pid || oldPid==padre || countChar(name) != countChar(start) ) { //brake a 0 anche se viene rilevata una start che non è stata lanciata da terminale ma è in esecuzione de un po
|
||||
brake = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//questo ci serve per andare a salvare il pid di una nuova start lanciata da terminale
|
||||
//il primissimo start viene detectato OR detecta uno start con un pid nuovo
|
||||
if((oldPid==-1 && brake == 0) || (oldPid!=-1 && brake == 0 && oldPid!=pid) )
|
||||
//il primissimo start viene detectato OR detecta uno start con un pid nuovo MA con mio padre diverso dal creatore della sessione attuale o finita (oldPid)
|
||||
if((oldPid==-1 && brake == 0) || (oldPid!=-1 && brake == 0 && oldPid!=pid && oldPid!=padre) ){
|
||||
|
||||
oldPid = pid;
|
||||
|
||||
}
|
||||
|
||||
//Entra solo una volta, dopo aver finito la sessione (riempito il buffer) e richiesta una nuova
|
||||
if (brake == 0 && count == MAX_STORAGE) {
|
||||
@@ -72,7 +78,9 @@ void writeFeedback(pid_t pid, char name[])
|
||||
//RESET BUFFER
|
||||
for (int i = 0; i < MAX_STORAGE; i++) {
|
||||
PID_BUFFER[i] = 0;
|
||||
PID_PRIO[i] = 0;
|
||||
}
|
||||
err = 1;
|
||||
count = 0;
|
||||
}
|
||||
|
||||
@@ -81,9 +89,10 @@ void writeFeedback(pid_t pid, char name[])
|
||||
//Se prima volta e' start bene, proseguiamo siccome brake e' zero,
|
||||
//le successive brake NON zero ma count > 0 poiche start passato in precedenza
|
||||
//Opportuno controllo per non sforare il MAX_STORAGE della struttura dati che utilizziamo
|
||||
if (count != MAX_STORAGE && (count != 0 || brake == 0)) {
|
||||
//REGISTRAZIONE PID IN BUFFER
|
||||
if (count != MAX_STORAGE && (count != 0 || brake == 0 )) {
|
||||
//REGISTRAZIONE PID IN BUFFER in modalita start SENZA parametri
|
||||
PID_BUFFER[count] = pid;
|
||||
PID_PRIO[count] = prio;
|
||||
strcpy(PID_NAME[count], name);
|
||||
count++;
|
||||
}
|
||||
@@ -91,25 +100,57 @@ void writeFeedback(pid_t pid, char name[])
|
||||
//QUI SE BUFFER PIENO SCRIVO SU FILE
|
||||
|
||||
if (count == MAX_STORAGE) {
|
||||
mode_t mode = 000777;
|
||||
mode_t flag = 000777;
|
||||
char buffer[BUFFER_SIZE];
|
||||
const char *namef = "/home/user/feedback.txt";
|
||||
ssize_t offset = sizeof(char) * 38;
|
||||
offset = sizeof(char) * 34; //PER SCRITTURA MODALITA
|
||||
char temp[6]; //max PID 99999
|
||||
char temp_prio[4];
|
||||
char rr[] = "ROUND ROBIN\n";
|
||||
char priority[] = "HIGH PRIORITY FIRST\n";
|
||||
char cfs[] = "FAIR SHARE\n";
|
||||
char testo[] = "\nPID PRIO NAME\n";
|
||||
|
||||
// NOTE: You should check if the file exists, or create it, during the boot
|
||||
// phase of the system. Choose a place where to put it, a location like
|
||||
// `/var/scheduling_feedback.txt`.
|
||||
vfs_file_t *file = vfs_open(namef, O_RDWR, mode);
|
||||
vfs_file_t *file = vfs_open(namef, O_RDWR, flag);
|
||||
|
||||
if (file == NULL) {
|
||||
printf("Error: Failed to open feedback file.");
|
||||
}
|
||||
|
||||
if(mode == 1){
|
||||
|
||||
offset += vfs_write(file, " ", offset, sizeof(char));
|
||||
offset += vfs_write(file, rr, offset, sizeof(char)*countChar(rr));
|
||||
}
|
||||
else if(mode == 2){
|
||||
|
||||
offset += vfs_write(file, " ", offset, sizeof(char));
|
||||
offset += vfs_write(file, priority, offset, sizeof(char)*countChar(priority));
|
||||
}
|
||||
else{
|
||||
|
||||
offset += vfs_write(file, " ", offset, sizeof(char));
|
||||
offset += vfs_write(file, cfs, offset, sizeof(char)*countChar(cfs));
|
||||
}
|
||||
|
||||
/*
|
||||
offset += vfs_write(file, "\n", offset, sizeof(char));
|
||||
offset += vfs_write(file, "\n", offset, sizeof(char));
|
||||
offset += sizeof(char)* (13);*/
|
||||
|
||||
offset += vfs_write(file, testo, offset, sizeof(char)*countChar(testo));
|
||||
|
||||
|
||||
for (int i = 0; i < MAX_STORAGE; i++) {
|
||||
itoa(temp, PID_BUFFER[i], 10);
|
||||
itoa(temp_prio, PID_PRIO[i], 10);
|
||||
offset += vfs_write(file, temp, offset, sizeof(char) * countChar(temp));
|
||||
offset += vfs_write(file, " ", offset, sizeof(char) * 3);
|
||||
offset += vfs_write(file, temp_prio, offset, sizeof(char) * countChar(temp_prio));
|
||||
offset += vfs_write(file, " ", offset, sizeof(char) * 3);
|
||||
offset += vfs_write(file, PID_NAME[i], offset, sizeof(char) * countChar(PID_NAME[i]));
|
||||
offset += vfs_write(file, "\n", offset, sizeof(char));
|
||||
//ripristino array temp
|
||||
@@ -117,12 +158,35 @@ void writeFeedback(pid_t pid, char name[])
|
||||
temp[j] = 0;
|
||||
}
|
||||
}
|
||||
printf("End Recording\n");
|
||||
vfs_close(file);
|
||||
count = 0;
|
||||
}
|
||||
|
||||
if(!strcmp(name,"error") && err){
|
||||
|
||||
wipe();
|
||||
err--;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Funzione che pulisce la sessione
|
||||
*/
|
||||
void wipe()
|
||||
{
|
||||
mode_t flag = 000777;
|
||||
const char *namef = "/home/user/feedback.txt";
|
||||
vfs_file_t *file = vfs_open(namef, O_RDWR, flag);
|
||||
count = 0;
|
||||
|
||||
for(int i = 34*sizeof(char); i < offset; i+=sizeof(char)){
|
||||
|
||||
vfs_write(file, " ", i, sizeof(char));
|
||||
}
|
||||
vfs_close(file);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Funzione che conta caratteri del array di char passato
|
||||
*/
|
||||
|
||||
@@ -69,11 +69,7 @@ set(PROGRAMS
|
||||
poweroff.c
|
||||
rm.c
|
||||
shell.c
|
||||
|
||||
|
||||
start.c
|
||||
|
||||
|
||||
start.c
|
||||
uname.c
|
||||
cat.c
|
||||
echo.c
|
||||
|
||||
+39
-2
@@ -6,6 +6,9 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <sys/unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
Start, funzionamento: L'utente scrivendo start da shell (interna a MentOS) avviera' la registrazione di un numero
|
||||
@@ -18,9 +21,43 @@ Tre tipologie di parametri/flag accettati dalla start:
|
||||
|
||||
*/
|
||||
|
||||
int main()
|
||||
//int clonaccio(int, char *);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
//N.B va implementato il reset della struttura che alloca i dati(PID)
|
||||
printf("Avvio Recording\n");
|
||||
|
||||
//aka utente ha inserito un comando start con flag errati
|
||||
if(argc > 1 && (strcmp(argv[1],"-p") || strcmp(argv[1],"-f"))){
|
||||
printf("start has no command '%s'\n\n", argv[1]);
|
||||
execl("../../bin/startERR","error", NULL, NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Start Recording\n");
|
||||
|
||||
if(argc == 2){
|
||||
|
||||
if(!(strcmp(argv[1],"-p"))){
|
||||
|
||||
for(int i = 0; i < 5; i++){
|
||||
|
||||
if(fork()==0){
|
||||
|
||||
//volendo no fork qua, ma solo chiamata a t_fork 5 con una exec
|
||||
//execl("../../bin/start0", "figlio", NULL, NULL);
|
||||
exit(1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for(int i = 0; i < 5; i++){
|
||||
wait(NULL);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
printf("End Recording\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user