diff --git a/fall-2024/sys-arch/sys-102/00040/SYS-102 Assessment 1 - Thanawin Pattanaphol.odt b/fall-2024/sys-arch/sys-102/00040/SYS-102 Assessment 1 - Thanawin Pattanaphol.odt index 3f1b507..f6c61b7 100644 Binary files a/fall-2024/sys-arch/sys-102/00040/SYS-102 Assessment 1 - Thanawin Pattanaphol.odt and b/fall-2024/sys-arch/sys-102/00040/SYS-102 Assessment 1 - Thanawin Pattanaphol.odt differ diff --git a/fall-2024/sys-arch/sys-102/00040/source/interrupt b/fall-2024/sys-arch/sys-102/00040/source/interrupt index 333ef08..3794048 100755 Binary files a/fall-2024/sys-arch/sys-102/00040/source/interrupt and b/fall-2024/sys-arch/sys-102/00040/source/interrupt differ diff --git a/fall-2024/sys-arch/sys-102/00040/source/interrupt.c b/fall-2024/sys-arch/sys-102/00040/source/interrupt.c index 1e76c8d..961e070 100644 --- a/fall-2024/sys-arch/sys-102/00040/source/interrupt.c +++ b/fall-2024/sys-arch/sys-102/00040/source/interrupt.c @@ -3,47 +3,50 @@ #include #include -clock_t t; -t = clock(); - +// Declare Variables int flag = 0; +int lap = 0; + // Handling signal function void handle_signal(int signal) { // If signal is SIGINT - if (signal == SIGQUIT) + if (signal == SIGINT) { // Set flag to its complement // Print the flag value flag = !flag; + lap++; printf("Flag: %d\n", flag); } - if (signal == SIGINT) + if (signal == SIGQUIT) { - t = clock() - t; - double time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds - printf("CPU Time: %f\n", t); _exit(0); } } int main() { + clock_t start, end; + double cpu_time_used; + + start = clock(); + // Handling signal - signal(SIGQUIT, handle_signal); signal(SIGINT, handle_signal); + signal(SIGQUIT, handle_signal); // Let the program run until interrupt - while (1) + while (lap < 10) { sleep(1); - } + } - //t = clock() - t; - //double time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds + end = clock(); + cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; - printf("CPU Time: %f\n", t); + printf("CPU Time: %f\n", cpu_time_used); return 0; } diff --git a/fall-2024/sys-arch/sys-102/00040/source/polling b/fall-2024/sys-arch/sys-102/00040/source/polling index 6e463a4..8602244 100755 Binary files a/fall-2024/sys-arch/sys-102/00040/source/polling and b/fall-2024/sys-arch/sys-102/00040/source/polling differ diff --git a/fall-2024/sys-arch/sys-102/00040/source/polling.c b/fall-2024/sys-arch/sys-102/00040/source/polling.c index f43f46c..b46d34d 100644 --- a/fall-2024/sys-arch/sys-102/00040/source/polling.c +++ b/fall-2024/sys-arch/sys-102/00040/source/polling.c @@ -1,16 +1,23 @@ #include #include #include +#include int main() { + clock_t start, end; + double cpu_time_used; + + // Set start to current CPU time + start = clock(); + int c; int flag = 0; + int laps = 0; /* THIS IS A REPLACEMENT FOR THE _KBHIT FUNCTION - */ - + */ // These structs are for saving tty parameters static struct termios old_term, new_term; @@ -26,9 +33,12 @@ int main() tcsetattr(STDIN_FILENO, TCSANOW, &new_term); // Get character input by user - while ((c = getchar()) != EOF) + while ((c = getchar()) != EOF && laps < 10) { + // Flip the flag flag = !flag; + laps++; + printf("\n"); printf("Flag: %d\n", flag); } @@ -36,6 +46,11 @@ int main() // Done retriving input // Set tty parameters back to old tty parameters tcsetattr(STDIN_FILENO, TCSANOW, &old_term); + + end = clock(); + cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; + + printf("CPU Time: %f\n", cpu_time_used); return 0; } diff --git a/fall-2024/urd-101/.~lock.Med-D Revamp.odp# b/fall-2024/urd-101/.~lock.Med-D Revamp.odp# deleted file mode 100644 index 43bec31..0000000 --- a/fall-2024/urd-101/.~lock.Med-D Revamp.odp# +++ /dev/null @@ -1 +0,0 @@ -,winsdominoes,fedora,18.11.2024 11:44,file:///home/winsdominoes/.var/app/org.libreoffice.LibreOffice/config/libreoffice/4; \ No newline at end of file