Update Task
This commit is contained in:
@@ -3,22 +3,36 @@
|
||||
/// @copyright (c) 2014-2022 This file is distributed under the MIT License.
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
/*
|
||||
HOW TO:
|
||||
all'avvio di MentOS, usa comando start, verrai avvisato su terminale quando la sessione sarà terminata.
|
||||
Puoi verificare i risultati a video lanciando il comando cat sul file del desktop (feedback.txt)
|
||||
|
||||
es:
|
||||
~ start
|
||||
~ cat feedback.txt
|
||||
|
||||
Questa e' una versione di prova in cui registriamo una brevissima sessione di soli 10 pid.
|
||||
(Funzionante per ora solo con lo scheduler RR)
|
||||
Istruzioni relative ai parametri della funzione start (che sono work in progress) sono in start.c
|
||||
*/
|
||||
|
||||
#include "fcntl.h"
|
||||
#include "stdio.h"
|
||||
#include "fs/vfs.h"
|
||||
#include "string.h"
|
||||
|
||||
|
||||
// Size of the buffer.
|
||||
#define BUFFER_SIZE 256
|
||||
|
||||
#define MAX_SIZE_NAME 20
|
||||
|
||||
//Variabili Globali
|
||||
// Size of the buffer.
|
||||
//#define BUFFER_SIZE 256
|
||||
#define MAX_STORAGE 50
|
||||
#define MAX_STORAGE 10
|
||||
int count = 0;
|
||||
|
||||
int flag = 0;
|
||||
int count2 = 0;
|
||||
pid_t salvati[10] = {0};
|
||||
int i = 0;
|
||||
|
||||
|
||||
pid_t PID_BUFFER[MAX_STORAGE] = {0};
|
||||
char PID_NAME[MAX_STORAGE][MAX_SIZE_NAME];
|
||||
|
||||
int countChar(char[]);
|
||||
|
||||
@@ -38,86 +52,75 @@ void writeFeedback(pid_t pid, char name[])
|
||||
char start[] = "start";
|
||||
|
||||
//analizzo se nome del PID passato come argomento corrisponde al comando START
|
||||
for(int j = 0 ; j < countChar(name) && brake == 0; j++)
|
||||
for(int i = 0 ; i < countChar(name) && brake == 0; i++)
|
||||
{
|
||||
if(start[j] != name[j])
|
||||
if(start[i] != name[i])
|
||||
{
|
||||
brake = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//Entra solo una volta, ovvero la prima volta che viene dato start
|
||||
if(brake == 0 && count == MAX_STORAGE)
|
||||
//Entra solo una volta, dopo aver finito la sessione (riempito il buffer)
|
||||
if(brake == 0 && count == MAX_STORAGE-1)
|
||||
{
|
||||
//RESET BUFFER
|
||||
for(int i = 0; i < MAX_STORAGE; i++)
|
||||
{
|
||||
PID_BUFFER[i] = 0;
|
||||
}
|
||||
count = 0;
|
||||
|
||||
}
|
||||
|
||||
//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 ))
|
||||
if(count != MAX_STORAGE-1 && (count != 0 || brake == 0 ))
|
||||
{
|
||||
//REGISTRAZIONE PID IN BUFFER
|
||||
PID_BUFFER[count] = pid;
|
||||
strcpy(PID_NAME[count],name);
|
||||
count++;
|
||||
}
|
||||
|
||||
//QUI SE BUFFER PIENO SCRIVO SU FILE
|
||||
//QUI SOTTO PROBABILMENTE QUASI TUTTO DA CANCELLARE
|
||||
|
||||
if(pid != 1 && pid != 2)
|
||||
if(count == MAX_STORAGE-1)
|
||||
{
|
||||
flag = 1;
|
||||
}
|
||||
else if(i<10)
|
||||
{
|
||||
salvati[i] = pid;
|
||||
i++;
|
||||
mode_t mode = 000777;
|
||||
char buffer[BUFFER_SIZE];
|
||||
const char *namef = "/home/user/feedback.txt";
|
||||
ssize_t offset = sizeof(char)*38;
|
||||
char temp[6]; //max PID 99999
|
||||
|
||||
// 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);
|
||||
|
||||
if (file == NULL) {
|
||||
printf("Error: Failed to open feedback file.");
|
||||
}
|
||||
|
||||
for(int i=0; i < MAX_STORAGE; i++)
|
||||
{
|
||||
itoa(temp,PID_BUFFER[i],10);
|
||||
offset += vfs_write(file, temp, offset, sizeof(char)*countChar(temp));
|
||||
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
|
||||
for(int j=0; j < 5; j++)
|
||||
{
|
||||
temp[j] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
printf("End Recording\n");
|
||||
vfs_close(file);
|
||||
count = 0;
|
||||
}
|
||||
|
||||
|
||||
if(count2%10 == 0)
|
||||
{
|
||||
if(flag == 1 && pid != 1 && pid != 2)
|
||||
{
|
||||
//printf("%s con %d caratteri\n",name,countChar(name));
|
||||
//printf("%s\n",start);
|
||||
//printf("%i\n",pid);
|
||||
//printf("Ho stampato: %s\n", name);
|
||||
}
|
||||
}
|
||||
count2++;
|
||||
|
||||
|
||||
//ROBA PER LAVORARE SUI FILE
|
||||
/*
|
||||
mode_t mode = 000777;
|
||||
char buffer[BUFFER_SIZE];
|
||||
const char *name = "/home/user/feedback.txt";
|
||||
|
||||
// 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(name, O_RDWR, mode);
|
||||
|
||||
if (file == NULL) {
|
||||
printf("Error: Failed to open feedback file.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// NOTE: You need also to save the offset where you are reading or writing
|
||||
// the file. You are not using the simplified read() or write(), this one is
|
||||
// a kernel-side function.
|
||||
ssize_t offset = 0;
|
||||
buffer[0] = 'P';
|
||||
buffer[1] = 'i';
|
||||
buffer[2] = 'd';
|
||||
buffer[3] = '\0';
|
||||
vfs_write(file, buffer, offset, 2);
|
||||
|
||||
//write to file
|
||||
//vfs_write(file,"ciao",4);
|
||||
vfs_close(file);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user