From 7d42f510ad10d8f4c180efb4964464b237c782cc Mon Sep 17 00:00:00 2001 From: emil28092005 <65846814+emil28092005@users.noreply.github.com> Date: Tue, 1 Oct 2024 20:02:11 +0300 Subject: [PATCH] Lab6 --- .idea/OS.iml | 2 - .idea/encodings.xml | 7 ++++ CMakeLists.txt | 3 +- Lab6/agent.c | 36 ++++++++++++++++++ Lab6/controller.c | 3 ++ Lab6/example1.c | 28 ++++++++++++++ cmake-build-debug/.ninja_deps | Bin 4620 -> 3120 bytes cmake-build-debug/.ninja_log | 30 +++++++++++++-- .../Testing/Temporary/LastTest.log | 4 +- cmake-build-debug/build.ninja | 8 ++-- 10 files changed, 108 insertions(+), 13 deletions(-) delete mode 100644 .idea/OS.iml create mode 100644 .idea/encodings.xml create mode 100644 Lab6/agent.c create mode 100644 Lab6/controller.c create mode 100644 Lab6/example1.c diff --git a/.idea/OS.iml b/.idea/OS.iml deleted file mode 100644 index f08604b..0000000 --- a/.idea/OS.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..39f8b34 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 57bd749..75d5bb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,4 +8,5 @@ SET(GCC_COVERAGE_COMPILE_FLAGS "-pthread") add_executable(OS - Lab5/ex4.c) + Lab6/agent.c + Lab6/agent.c) diff --git a/Lab6/agent.c b/Lab6/agent.c new file mode 100644 index 0000000..fc95658 --- /dev/null +++ b/Lab6/agent.c @@ -0,0 +1,36 @@ +#include +#include + +int main() { + /* + On startup, the agent program creates the file +/var/run/agent.pid and writes its PID into the file. It then reads +the contents of a file called text.txt, prints it on the console and +finally sleeps indefinitely + */ + FILE *file = fopen("text.txt", "w"); + FILE *filePid = fopen("agent.txt", "w"); + fputc(getpid(), filePid); + fclose(filePid); + fclose(file); + char pid_str[10]; + fgets(pid_str, sizeof(pid_str), file); + fclose(file); + + FILE *text_file = fopen("text.txt", "r"); + if (text_file == NULL) { + printf("Error opening text.txt\n"); + return 1; + } + + char c; + while ((c = fgetc(text_file))!= EOF) + printf("%c", c); + + fclose(text_file); + + printf("\nSleeping indefinitely...\n"); + while (1) + sleep(1); + return 0; +} \ No newline at end of file diff --git a/Lab6/controller.c b/Lab6/controller.c new file mode 100644 index 0000000..7d00d1b --- /dev/null +++ b/Lab6/controller.c @@ -0,0 +1,3 @@ +// +// Created by emil on 01.10.2024. +// diff --git a/Lab6/example1.c b/Lab6/example1.c new file mode 100644 index 0000000..d558c0e --- /dev/null +++ b/Lab6/example1.c @@ -0,0 +1,28 @@ +#include + +int main() { + /* + * Write a C program that prints “Hello world!” an infinite number +of times. +Run the program, and kill it by pressing (Ctrl+C). Which signal +did the process receive? Can we handle it? Can the process ignore +the signal? +Run the program, and kill it by pressing (Ctrl+\). Which signal +did the process receive? Can we handle it? Can the process ignore +the signal? In Ubuntu, set core dump size via ulimit -c +unlimited. The core dump file is in /var/lib/apport/coredump/. +Check the log file /var/log/apport.log for core dump file name. +Run the program in the background (&) and redirect stdout to a +file output.txt, kill the process by sending the signal “SIGTERM” +via “kill -s SIGTERM pid ” command. Can we handle the +signal? Can the process ignore the signal? Send the signal +“SIGKILL” if the program does not terminate politely. +30 / 58 + */ + + + while (1) + printf("Hello world!\n"); + + return 0; +} \ No newline at end of file diff --git a/cmake-build-debug/.ninja_deps b/cmake-build-debug/.ninja_deps index c3e25a2db4980051dd1f51eefe32f58427d311e3..95e53dd770a87b6db58a0ca8752b3f86717b2916 100644 GIT binary patch delta 337 zcmeBC*&s1Nlif@|F+DY}WTJsK7nG@&{BN=&qsYceWtPcDxCAGkb<92uP0a4z z5s_>(v4CLrQzd9(o5CjjX+sm6n|@^faWt{BmdE`*qlryi5X1fpP0V23q6e%AV1EDr D5&(B6 literal 4620 zcmeI0=X2ad7>73y0wi<-p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Al+Ie|H+Ug>-10EXgc71}SHo}Xk2K`?B2(j6VO(?9iI|VsqM=>^Z)p*a_?m<^g$^>TV1_r_D;0$mk zI18K&&H?8Fxi;-@1r_;A0U?*5KB~9Ne=EQYLN3nhc^+b4$k)$VhkBlm|NpP&e_zjk E06Q`Ja{vGU diff --git a/cmake-build-debug/.ninja_log b/cmake-build-debug/.ninja_log index ead96b2..459d0ba 100644 --- a/cmake-build-debug/.ninja_log +++ b/cmake-build-debug/.ninja_log @@ -2,10 +2,32 @@ 1 59 1727194503928197251 CMakeFiles/OS.dir/Lab5/ex2-3.c.o 3ac11e55017104db 1 69 1727194450713397978 CMakeFiles/OS.dir/Lab5/ex2.c.o aaf388779ce03a6e 1 54 1727193068898104463 CMakeFiles/OS.dir/Lab5/ex1.c.o 87ce1149fbd620b +1 53 1727797041565849223 CMakeFiles/OS.dir/Lab6/example1.c.o 6be6e05f0bf8623a 1 81 1727191541519747212 CMakeFiles/OS.dir/Lab4/ex1.c.o fdfe48b329a854c3 1 50 1726585076082163985 CMakeFiles/OS.dir/main.c.o 597d2975f9346988 -1 31 1727195105069329767 build.ninja 102e4adb4b6285fe -59 91 1727194503984862096 OS 7e7768c095bc6d8a -1 36 1727195105069329767 build.ninja 102e4adb4b6285fe +1 32 1727798122261377224 build.ninja 102e4adb4b6285fe +54 100 1727797041615835169 OS 87096d11c57d1daa 0 63 1727195105082663185 CMakeFiles/OS.dir/Lab5/ex4.c.o 60daafb2653af2a5 -63 96 1727195105142663566 OS 5ac1e89d9f8b3dbb +2 36 1727796978102865786 CMakeFiles/OS.dir/Lab6/controller.c.o e3d69d5ce71c382d +1 77 1727798135878055008 CMakeFiles/OS.dir/Lab6/agent.c.o f04cc81de1844813 +77 120 1727798135954721726 OS d21dc05418483373 +0 51 1727798170544732035 CMakeFiles/OS.dir/Lab6/agent.c.o f04cc81de1844813 +51 95 1727798170594732034 OS d21dc05418483373 +1 58 1727798268007998305 CMakeFiles/OS.dir/Lab6/agent.c.o f04cc81de1844813 +58 95 1727798268064664903 OS d21dc05418483373 +1 60 1727798299751289808 CMakeFiles/OS.dir/Lab6/agent.c.o f04cc81de1844813 +61 103 1727798299811289723 OS d21dc05418483373 +1 58 1727798320507925611 CMakeFiles/OS.dir/Lab6/agent.c.o f04cc81de1844813 +58 99 1727798320564592190 OS d21dc05418483373 +1 56 1727798362207857032 CMakeFiles/OS.dir/Lab6/agent.c.o f04cc81de1844813 +56 95 1727798362264523600 OS d21dc05418483373 +1 57 1727798440361045239 CMakeFiles/OS.dir/Lab6/agent.c.o f04cc81de1844813 +58 94 1727798440417711794 OS d21dc05418483373 +1 58 1727798718513790447 CMakeFiles/OS.dir/Lab6/agent.c.o f04cc81de1844813 +58 93 1727798718570456989 OS d21dc05418483373 +1 59 1727798905596710944 CMakeFiles/OS.dir/Lab6/agent.c.o f04cc81de1844813 +59 93 1727798905656710811 OS d21dc05418483373 +1 57 1727798934466646963 CMakeFiles/OS.dir/Lab6/agent.c.o f04cc81de1844813 +57 94 1727798934523313503 OS d21dc05418483373 +1 58 1727798985353200771 CMakeFiles/OS.dir/Lab6/agent.c.o f04cc81de1844813 +59 93 1727798985409867312 OS d21dc05418483373 diff --git a/cmake-build-debug/Testing/Temporary/LastTest.log b/cmake-build-debug/Testing/Temporary/LastTest.log index 28fb3ad..2e83f8c 100644 --- a/cmake-build-debug/Testing/Temporary/LastTest.log +++ b/cmake-build-debug/Testing/Temporary/LastTest.log @@ -1,3 +1,3 @@ -Start testing: Sep 24 19:25 MSK +Start testing: Oct 01 20:02 MSK ---------------------------------------------------------- -End testing: Sep 24 19:25 MSK +End testing: Oct 01 20:02 MSK diff --git a/cmake-build-debug/build.ninja b/cmake-build-debug/build.ninja index aa70532..2cf37d5 100644 --- a/cmake-build-debug/build.ninja +++ b/cmake-build-debug/build.ninja @@ -49,11 +49,11 @@ cmake_ninja_workdir = /home/emil/CLionProjects/OS/cmake-build-debug/ build cmake_object_order_depends_target_OS: phony || . -build CMakeFiles/OS.dir/Lab5/ex4.c.o: C_COMPILER__OS_unscanned_Debug /home/emil/CLionProjects/OS/Lab5/ex4.c || cmake_object_order_depends_target_OS - DEP_FILE = CMakeFiles/OS.dir/Lab5/ex4.c.o.d +build CMakeFiles/OS.dir/Lab6/agent.c.o: C_COMPILER__OS_unscanned_Debug /home/emil/CLionProjects/OS/Lab6/agent.c || cmake_object_order_depends_target_OS + DEP_FILE = CMakeFiles/OS.dir/Lab6/agent.c.o.d FLAGS = -g -std=gnu11 -fdiagnostics-color=always OBJECT_DIR = CMakeFiles/OS.dir - OBJECT_FILE_DIR = CMakeFiles/OS.dir/Lab5 + OBJECT_FILE_DIR = CMakeFiles/OS.dir/Lab6 # ============================================================================= @@ -63,7 +63,7 @@ build CMakeFiles/OS.dir/Lab5/ex4.c.o: C_COMPILER__OS_unscanned_Debug /home/emil/ ############################################# # Link the executable OS -build OS: C_EXECUTABLE_LINKER__OS_Debug CMakeFiles/OS.dir/Lab5/ex4.c.o +build OS: C_EXECUTABLE_LINKER__OS_Debug CMakeFiles/OS.dir/Lab6/agent.c.o FLAGS = -g OBJECT_DIR = CMakeFiles/OS.dir POST_BUILD = :