diff --git a/fall-2024/sys-arch/sys-102/00040/.~lock.SYS-102 Assessment 1 - Thanawin Pattanaphol.odt# b/fall-2024/sys-arch/sys-102/00040/.~lock.SYS-102 Assessment 1 - Thanawin Pattanaphol.odt# index 979527e..02dc304 100644 --- a/fall-2024/sys-arch/sys-102/00040/.~lock.SYS-102 Assessment 1 - Thanawin Pattanaphol.odt# +++ b/fall-2024/sys-arch/sys-102/00040/.~lock.SYS-102 Assessment 1 - Thanawin Pattanaphol.odt# @@ -1 +1 @@ -,winsdominoes,fedora,17.11.2024 20:23,file:///home/winsdominoes/.var/app/org.libreoffice.LibreOffice/config/libreoffice/4; \ No newline at end of file +,winsdominoes,fedora,17.11.2024 20:55,file:///home/winsdominoes/.var/app/org.libreoffice.LibreOffice/config/libreoffice/4; \ No newline at end of file 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 0f169e5..6d93a79 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/a.out b/fall-2024/sys-arch/sys-102/00040/source/a.out new file mode 100755 index 0000000..61fef47 Binary files /dev/null and b/fall-2024/sys-arch/sys-102/00040/source/a.out differ diff --git a/fall-2024/sys-arch/sys-102/00040/source/interrupt b/fall-2024/sys-arch/sys-102/00040/source/interrupt new file mode 100755 index 0000000..333ef08 Binary files /dev/null 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 new file mode 100644 index 0000000..1e76c8d --- /dev/null +++ b/fall-2024/sys-arch/sys-102/00040/source/interrupt.c @@ -0,0 +1,49 @@ +#include +#include +#include +#include + +clock_t t; +t = clock(); + +int flag = 0; +// Handling signal function +void handle_signal(int signal) +{ + // If signal is SIGINT + if (signal == SIGQUIT) + { + // Set flag to its complement + // Print the flag value + flag = !flag; + printf("Flag: %d\n", flag); + } + + if (signal == SIGINT) + { + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds + printf("CPU Time: %f\n", t); + _exit(0); + } +} + +int main() +{ + // Handling signal + signal(SIGQUIT, handle_signal); + signal(SIGINT, handle_signal); + + // Let the program run until interrupt + while (1) + { + sleep(1); + } + + //t = clock() - t; + //double time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds + + printf("CPU Time: %f\n", t); + + return 0; +} diff --git a/fall-2024/sys-arch/sys-102/00040/source/interrupt.c~ b/fall-2024/sys-arch/sys-102/00040/source/interrupt.c~ new file mode 100644 index 0000000..83901c8 --- /dev/null +++ b/fall-2024/sys-arch/sys-102/00040/source/interrupt.c~ @@ -0,0 +1,45 @@ +#include +#include +#include +#include + +int flag = 0; +// Handling signal function +void handle_signal(int signal) +{ + // If signal is SIGINT + if (signal == SIGQUIT) + { + // Set flag to its complement + // Print the flag value + flag = !flag; + printf("Flag: %d\n", flag); + } + + if (signal == SIGINT) + { + _exit(0); + } +} + +int main() +{ + clock_t t; + t = clock(); + // Handling signal + signal(SIGQUIT, handle_signal); + signal(SIGINT, handle_signal); + + // Let the program run until interrupt + while (1) + { + sleep(1); + } + + t = clock() - t; + double time_taken = ((double)t)/CLOCKS_PER_SEC; // in seconds + + printf("CPU Time: %f\n", t); + + return 0; +} diff --git a/fall-2024/sys-arch/sys-102/00040/source/interrupts.c~ b/fall-2024/sys-arch/sys-102/00040/source/interrupts.c~ new file mode 100644 index 0000000..0589129 --- /dev/null +++ b/fall-2024/sys-arch/sys-102/00040/source/interrupts.c~ @@ -0,0 +1,7 @@ +#include +#include +#include + +void handle_signal(int signal) { + +} diff --git a/fall-2024/sys-arch/sys-102/00040/source/polling b/fall-2024/sys-arch/sys-102/00040/source/polling new file mode 100755 index 0000000..6e463a4 Binary files /dev/null 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 new file mode 100644 index 0000000..f43f46c --- /dev/null +++ b/fall-2024/sys-arch/sys-102/00040/source/polling.c @@ -0,0 +1,41 @@ +#include +#include +#include + +int main() +{ + int c; + int flag = 0; + + /* + THIS IS A REPLACEMENT FOR THE _KBHIT FUNCTION + */ + + // These structs are for saving tty parameters + static struct termios old_term, new_term; + + // Get parameters associated with the tty + // Set the new tty parameters to the old one + tcgetattr(STDIN_FILENO, &old_term); + new_term = old_term; + + // Set the new tty parameters to canonical mode + new_term.c_lflag &= ~(ICANON); + + // Set tty attributes + tcsetattr(STDIN_FILENO, TCSANOW, &new_term); + + // Get character input by user + while ((c = getchar()) != EOF) + { + flag = !flag; + printf("\n"); + printf("Flag: %d\n", flag); + } + + // Done retriving input + // Set tty parameters back to old tty parameters + tcsetattr(STDIN_FILENO, TCSANOW, &old_term); + + return 0; +} diff --git a/fall-2024/sys-arch/sys-102/00040/source/polling.c~ b/fall-2024/sys-arch/sys-102/00040/source/polling.c~ new file mode 100644 index 0000000..f13c3e1 --- /dev/null +++ b/fall-2024/sys-arch/sys-102/00040/source/polling.c~ @@ -0,0 +1,40 @@ +#include +#include +#include + +int main() +{ + int c; + int flag = 0; + + /* + THIS IS A REPLACEMENT FOR THE _KBHIT FUNCTION + */ + + // These structs are for saving tty parameters + static struct termios old_term, new_term; + + // Get parameters associated with the tty + // Set the new tty parameters to the old one + tcgetattr(STDIN_FILENO, &old_term); + new_term = old_term; + + // Set the new tty parameters to canonical mode + new_term.c_lflag &= ~(ICANON); + + // Set tty attributes + tcsetattr(STDIN_FILENO, TCSANOW, &new_term); + + // Get character input by user + while ((c = getchar()) != EOF) + { + flag = !flag; + printf("Flag: %d\n", flag); + } + + // Done retriving input + // Set tty parameters back to old tty parameters + tcsetattr(STDIN_FILENO, TCSANOW, &old_term); + + return 0; +}