├── .clang-format ├── .gitignore ├── ANCILLARY MATERIALS - TASKS AND LECTURES(XD) ├── exam │ ├── Biblia, księga Koźlaka.pdf │ ├── Opracowanie zerówka 16_2F17.pdf │ ├── OpracowanieSysopy.pdf │ └── Sysopy-opracowanko.pdf ├── lectures(xD) │ ├── Lectures 2017-2018 │ │ ├── Readme.md │ │ ├── Wyklad1v2.pdf │ │ ├── Wyklad2v2.pdf │ │ ├── Wyklad3v4.pdf │ │ ├── Wyklad4.pdf │ │ ├── Wyklad5.pdf │ │ ├── Wyklad6.pdf │ │ ├── Wyklad7v4.pdf │ │ └── Wyklad8.pdf │ ├── Lectures 2018-2019 │ │ ├── Readme.md │ │ ├── Wyklad1.pdf │ │ ├── Wyklad2.pdf │ │ ├── Wyklad3.pdf │ │ ├── Wyklad4.pdf │ │ ├── Wyklad5.pdf │ │ ├── Wyklad6.pdf │ │ ├── Wyklad7.pdf │ │ └── Wyklad8.pdf │ └── Readme.md └── tasks │ ├── FileSystem.pdf │ ├── Libraries - static, dynamic, shared, Make.pdf │ ├── MessageQueues.md │ ├── Mutual Exclusions, Condition Variables.md │ ├── Pipelines.md │ ├── Processes.md │ ├── Readme.md │ ├── Semaphores.md │ ├── Signals.pdf │ ├── Sockets.md │ ├── Threads.md │ └── pdf_files │ ├── FileSystem.pdf │ ├── Libraries - static, dynamic, shared, Make.pdf │ ├── MessageQueues.pdf │ ├── Mutual Exclusions, Condition Variables.pdf │ ├── Pipelines.pdf │ ├── Pipelines_v2.pdf │ ├── Processes.pdf │ ├── Processes_v2.pdf │ ├── Semaphores.pdf │ ├── Signals.pdf │ ├── Sockets.pdf │ └── Threads.pdf ├── CMakeLists.txt ├── KOLOSY_SOLUSZYNS ├── tests_17_18 │ ├── test_1 │ │ ├── KolosEom │ │ │ ├── zad1(ok) │ │ │ │ ├── Makefile │ │ │ │ └── main.c │ │ │ ├── zad2(ok) │ │ │ │ ├── Makefile │ │ │ │ └── main.c │ │ │ └── zad3(ok) │ │ │ │ ├── Makefile │ │ │ │ └── main.c │ │ ├── KozlakSroda9:35 │ │ │ ├── zad1(ok) │ │ │ │ ├── Makefile │ │ │ │ └── main.c │ │ │ ├── zad2(ok) │ │ │ │ ├── Makefile │ │ │ │ └── main.c │ │ │ └── zad3(ok) │ │ │ │ ├── Makefile │ │ │ │ └── main.c │ │ ├── SiwikWtorek14:40 │ │ │ ├── zad1(ok) │ │ │ │ ├── Makefile │ │ │ │ └── main.c │ │ │ ├── zad2(ok) - to samo co KozlakSroda9:35zad3 │ │ │ │ ├── Makefile │ │ │ │ └── main.c │ │ │ └── zad3(ok) │ │ │ │ ├── Makefile │ │ │ │ └── main.c │ │ └── kolospoprawkowyzforum │ │ │ ├── zad2(ok) │ │ │ ├── Makefile │ │ │ ├── receiver.c │ │ │ └── sender.c │ │ │ └── zad3(ok) │ │ │ ├── Makefile │ │ │ └── main.c │ └── test_2 │ │ ├── EOM(ok) │ │ ├── zad1(ok) │ │ │ ├── Makefile │ │ │ └── main.c │ │ ├── zad2(ok) │ │ │ ├── Makefile │ │ │ └── main.c │ │ └── zad3(ok) │ │ │ ├── Makefile │ │ │ └── main.c │ │ ├── JK(ok) │ │ ├── zad1(ok) │ │ │ ├── Makefile │ │ │ └── zad1.c │ │ ├── zad2(ok) │ │ │ ├── Makefile │ │ │ └── zad2.c │ │ └── zad3(ok) │ │ │ ├── Makefile │ │ │ └── main.c │ │ ├── S_1(ok) │ │ ├── zad1(ok) │ │ │ ├── Makefile │ │ │ └── main.c │ │ ├── zad2(ok) │ │ │ ├── Makefile │ │ │ ├── receiver.c │ │ │ └── sender.c │ │ └── zad3(ok) │ │ │ ├── Makefile │ │ │ └── main.c │ │ └── S_2(ok) │ │ ├── zad1(ok) │ │ ├── Makefile │ │ └── main.c │ │ ├── zad2(ok) │ │ ├── Makefile │ │ ├── receiver.c │ │ └── sender.c │ │ └── zad3(ok) │ │ ├── Makefile │ │ ├── receiver.c │ │ └── sender.c └── tests_18_19 │ ├── mytest_1 │ ├── Readme.md │ ├── zad1(ok) │ │ ├── Makefile │ │ └── main.c │ ├── zad2(ok) │ │ ├── Makefile │ │ └── main.c │ └── zad3(ok) │ │ ├── Makefile │ │ └── main.c │ └── mytest_2 │ ├── Readme.md │ ├── zad1(ok) │ ├── Makefile │ └── main.c │ ├── zad2(ok) │ ├── Makefile │ └── main.c │ └── zad3(ok) │ ├── Makefile │ └── main.c ├── README.md ├── cw01 ├── Readme.md ├── ancillary materials │ └── Libraries - static, dynamic, shared, Make.pdf ├── zad1 │ ├── Makefile │ ├── Readme.md │ ├── lib.c │ └── lib.h ├── zad2 │ ├── Makefile │ ├── Readme.md │ ├── lib.c │ ├── lib.h │ ├── lib_dynamic.h │ └── main.c └── zad3 │ ├── Readme.md │ ├── zad3a │ ├── Makefile │ ├── lib.c │ ├── lib.h │ ├── lib_dynamic.h │ └── main.c │ └── zad3b │ ├── Makefile │ ├── lib.c │ ├── lib.h │ ├── lib_dynamic.h │ └── main.c ├── cw02 ├── Readme.md ├── ancillary materials │ └── FileSystem.pdf ├── zad1 │ ├── Makefile │ ├── Readme.md │ └── main.c └── zad2 │ ├── Makefile │ ├── Readme.md │ └── main.c ├── cw03 ├── Readme.md ├── ancillary materials │ ├── Processes.md │ ├── Processes.pdf │ └── Processes_v2.pdf ├── zad1 │ ├── Makefile │ ├── Readme.md │ └── main.c ├── zad2 │ ├── Makefile │ ├── Readme.md │ ├── list.txt │ ├── main.c │ └── test │ │ ├── test │ │ ├── test1 │ │ └── test2 └── zad3 │ ├── Makefile │ ├── Readme.md │ ├── backup.c │ ├── backup.h │ ├── error.c │ ├── error.h │ ├── monitor.c │ └── tester.c ├── cw04 ├── Readme.md ├── ancillary materials │ └── Signals.pdf ├── zad1a │ ├── Makefile │ ├── Readme.md │ └── main.c ├── zad1b │ ├── Makefile │ ├── Readme.md │ ├── main.c │ └── print_date.sh ├── zad2 │ ├── Makefile │ ├── Readme.md │ ├── backup.c │ ├── backup.h │ ├── error.c │ ├── error.h │ ├── monitor.c │ └── tester.c ├── zad3a │ ├── Makefile │ ├── Readme.md │ ├── catcher.c │ ├── sender.c │ ├── utils.c │ └── utils.h └── zad3b │ ├── .idea │ ├── misc.xml │ ├── modules.xml │ ├── vcs.xml │ ├── workspace.xml │ └── zad3b.iml │ ├── Makefile │ ├── Readme.md │ ├── catcher.c │ ├── sender.c │ ├── utils.c │ └── utils.h ├── cw05 ├── Readme.md ├── ancillary materials │ ├── Pipelines.md │ ├── Pipelines.pdf │ └── Pipelines_v2.pdf ├── lab │ ├── Makefile │ ├── main.c │ └── result.txt ├── zad1 │ ├── Makefile │ ├── Readme.md │ ├── commands.txt │ └── main.c └── zad2 │ ├── Makefile │ ├── Readme.md │ ├── master.c │ ├── slave.c │ ├── utils.c │ └── utils.h ├── cw06 ├── Readme.md ├── ancillary_materials │ ├── MessageQueues.md │ └── MessageQueues.pdf ├── zad1 │ ├── Makefile │ ├── Readme.md │ ├── client.c │ ├── commands.txt │ ├── commands2.txt │ ├── helper.h │ └── server.c └── zad2 │ ├── Makefile │ ├── Readme.md │ ├── client.c │ ├── commands.txt │ ├── commands2.txt │ ├── helper.h │ └── server.c ├── cw07 ├── Readme.md ├── ancillary_materials │ ├── Semaphores.md │ └── Semaphores.pdf ├── lab │ └── main.c ├── zad1 │ ├── Makefile │ ├── Readme.md │ ├── conveyor_belt.c │ ├── conveyor_belt.h │ ├── error.c │ ├── error.h │ ├── loader.c │ ├── pack.c │ ├── pack.h │ ├── shared.h │ ├── spawner.c │ ├── systemv.c │ ├── trucker.c │ ├── utils.c │ └── utils.h └── zad2 │ ├── Makefile │ ├── Readme.md │ └── posix.c ├── cw08 ├── Readme.md ├── ancillary_materials │ ├── Threads.md │ └── Threads.pdf ├── zad1_additional_things_done │ ├── Makefile │ ├── Readme.md │ ├── errors.c │ ├── errors.h │ ├── filter.c │ ├── filter.h │ ├── filters │ │ ├── edge_detection.txt │ │ ├── emboss.txt │ │ ├── gaussian_blur.txt │ │ ├── none.txt │ │ ├── sharpen.txt │ │ └── simple_blur.txt │ ├── filters_generator.c │ ├── gaussian_filter.c │ ├── gaussian_filter.h │ ├── generate_report.sh │ ├── generated_filters │ │ └── .keep │ ├── image.c │ ├── image.h │ ├── images │ │ ├── balloons.ascii.pgm │ │ ├── lena.ascii.pgm │ │ ├── lena.ascii.ppm │ │ └── script.sh │ ├── images_out │ │ └── .keep │ ├── main.c │ ├── test.c │ ├── utils.c │ └── utils.h └── zad1_only_necessary_things_done │ ├── Makefile │ ├── Readme.md │ ├── edge.fil │ ├── error.c │ ├── error.h │ ├── filter.c │ ├── gauss.fil │ ├── mona.pgm │ ├── mona_edge.pgm │ ├── mona_gauss.pgm │ ├── mona_sharpen.pgm │ ├── sharpen.fil │ └── times.txt ├── cw09 ├── Readme.md ├── ancillary_materials │ ├── Mutual Exclusions, Condition Variables.md │ └── Mutual Exclusions, Condition Variables.pdf └── zad1 │ ├── Makefile │ ├── Readme.md │ ├── error.c │ ├── error.h │ └── roller_coaster.c ├── cw10 ├── Readme.md ├── ancillary_materials │ ├── Sockets.md │ └── Sockets.pdf ├── another_solution │ ├── zad1 │ │ ├── Makefile │ │ ├── Readme.md │ │ ├── a.txt │ │ ├── b.txt │ │ ├── client.c │ │ ├── error.c │ │ ├── error.h │ │ ├── proto.c │ │ ├── proto.h │ │ ├── queue.h │ │ └── server.c │ └── zad2 │ │ ├── Makefile │ │ ├── Readme.md │ │ ├── client.c │ │ ├── proto.c │ │ ├── proto.h │ │ └── server.c └── complete_sollution │ ├── zad1 │ ├── Makefile │ ├── Readme.md │ ├── chronicles_of_narnia.txt │ ├── client.c │ ├── colors.c │ ├── colors.h │ ├── errors.c │ ├── errors.h │ ├── queue.c │ ├── queue.h │ ├── server.c │ ├── utils.c │ └── utils.h │ └── zad2 │ ├── Makefile │ ├── Readme.md │ └── chronicles_of_narnia.txt └── format.sh /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Chromium 2 | ColumnLimit: 80 3 | IndentWidth: 4 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.so 3 | *.a 4 | *.o -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/exam/Biblia, księga Koźlaka.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/exam/Biblia, księga Koźlaka.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/exam/Opracowanie zerówka 16_2F17.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/exam/Opracowanie zerówka 16_2F17.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/exam/OpracowanieSysopy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/exam/OpracowanieSysopy.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/exam/Sysopy-opracowanko.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/exam/Sysopy-opracowanko.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2017-2018/Readme.md: -------------------------------------------------------------------------------- 1 | # xDDDDDD 2 | ### idk what for, srsly -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2017-2018/Wyklad1v2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2017-2018/Wyklad1v2.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2017-2018/Wyklad2v2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2017-2018/Wyklad2v2.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2017-2018/Wyklad3v4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2017-2018/Wyklad3v4.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2017-2018/Wyklad4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2017-2018/Wyklad4.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2017-2018/Wyklad5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2017-2018/Wyklad5.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2017-2018/Wyklad6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2017-2018/Wyklad6.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2017-2018/Wyklad7v4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2017-2018/Wyklad7v4.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2017-2018/Wyklad8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2017-2018/Wyklad8.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2018-2019/Readme.md: -------------------------------------------------------------------------------- 1 | # xDDDDDD 2 | ### idk what for, srsly -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2018-2019/Wyklad1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2018-2019/Wyklad1.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2018-2019/Wyklad2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2018-2019/Wyklad2.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2018-2019/Wyklad3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2018-2019/Wyklad3.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2018-2019/Wyklad4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2018-2019/Wyklad4.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2018-2019/Wyklad5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2018-2019/Wyklad5.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2018-2019/Wyklad6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2018-2019/Wyklad6.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2018-2019/Wyklad7.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2018-2019/Wyklad7.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2018-2019/Wyklad8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Lectures 2018-2019/Wyklad8.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/lectures(xD)/Readme.md: -------------------------------------------------------------------------------- 1 | # xDDDDDD 2 | ### idk what for, srsly -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/FileSystem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/FileSystem.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/Libraries - static, dynamic, shared, Make.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/Libraries - static, dynamic, shared, Make.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/Readme.md: -------------------------------------------------------------------------------- 1 | #### Task 1 2 | - gcc/g++ compilator options. Tools: GDB, Make 3 | 4 | - memory management 5 | 6 | - libraries 7 | 8 | - time measurement 9 | 10 | https://github.com/jakubowiczish/sysopy/blob/master/ANCILLARY%20MATERIALS%20-%20TASKS%20AND%20LECTURES(XD)/tasks/Libraries%20-%20static%2C%20dynamic%2C%20shared%2C%20Make.pdf 11 | 12 | 13 | #### Task 2 14 | - Files 15 | 16 | https://github.com/jakubowiczish/sysopy/blob/master/ANCILLARY%20MATERIALS%20-%20TASKS%20AND%20LECTURES(XD)/tasks/FileSystem.pdf 17 | 18 | 19 | #### Task 3 20 | - Processes 21 | 22 | https://github.com/jakubowiczish/sysopy/blob/master/ANCILLARY%20MATERIALS%20-%20TASKS%20AND%20LECTURES(XD)/tasks/Processes.md 23 | 24 | 25 | #### Task 4 26 | - Signals 27 | 28 | https://github.com/jakubowiczish/sysopy/blob/master/ANCILLARY%20MATERIALS%20-%20TASKS%20AND%20LECTURES(XD)/tasks/Signals.pdf 29 | 30 | 31 | #### Task 5 32 | - Pipelines 33 | 34 | https://github.com/jakubowiczish/sysopy/blob/master/ANCILLARY%20MATERIALS%20-%20TASKS%20AND%20LECTURES(XD)/tasks/Pipelines.md 35 | 36 | 37 | #### Task 6 38 | - IPC (Inter Process Communication) - Message Queues 39 | 40 | https://github.com/jakubowiczish/sysopy/blob/master/ANCILLARY%20MATERIALS%20-%20TASKS%20AND%20LECTURES(XD)/tasks/MessageQueues.md 41 | 42 | 43 | #### Task 7 44 | - IPC - shared memory, semaphores 45 | 46 | https://github.com/jakubowiczish/sysopy/blob/master/ANCILLARY%20MATERIALS%20-%20TASKS%20AND%20LECTURES(XD)/tasks/Semaphores.md 47 | 48 | 49 | #### Task 8 50 | - Threads - basics 51 | 52 | https://github.com/jakubowiczish/sysopy/blob/master/ANCILLARY%20MATERIALS%20-%20TASKS%20AND%20LECTURES(XD)/tasks/Threads.md 53 | 54 | 55 | #### Task 9 56 | - Threads - synchronization methods 57 | 58 | https://github.com/jakubowiczish/sysopy/blob/master/ANCILLARY%20MATERIALS%20-%20TASKS%20AND%20LECTURES(XD)/tasks/Mutual%20Exclusions%2C%20Condition%20Variables.md 59 | 60 | -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/Signals.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/Signals.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/FileSystem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/FileSystem.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Libraries - static, dynamic, shared, Make.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Libraries - static, dynamic, shared, Make.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/MessageQueues.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/MessageQueues.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Mutual Exclusions, Condition Variables.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Mutual Exclusions, Condition Variables.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Pipelines.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Pipelines.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Pipelines_v2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Pipelines_v2.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Processes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Processes.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Processes_v2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Processes_v2.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Semaphores.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Semaphores.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Signals.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Signals.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Sockets.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Sockets.pdf -------------------------------------------------------------------------------- /ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Threads.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/ANCILLARY MATERIALS - TASKS AND LECTURES(XD)/tasks/pdf_files/Threads.pdf -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/KolosEom/zad1(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | main: main.o 5 | 6 | clean: 7 | rm -f main.o main 8 | 9 | test: main 10 | @echo -e "\n\nTESTING\n\n" 11 | ./main /home/jakub/CLionProjects/sysopy 12 | 13 | all: main test -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/KolosEom/zad1(ok)/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char* argv[]) { 7 | DIR* directory; 8 | if (argc != 2) { 9 | printf("Call %s path", argv[0]); 10 | return 1; 11 | } 12 | struct dirent* position; 13 | 14 | /* 15 | * Otwórz katalog, w przypadku błędu otwarcia zwróć błąd funkcji 16 | otwierającej i wartość 1. Wyświetl zawartość katalogu katalog, pomijając 17 | "." i ".." Jeśli podczas tej operacji wartość errno zostanie ustawiona, 18 | zwróć błąd funkcji czytającej oraz wartość 2*/ 19 | 20 | /* ADDED BY ME - FROM HERE */ 21 | 22 | char* directory_path = argv[1]; 23 | 24 | if ((directory = opendir(directory_path)) != NULL) { 25 | while ((position = readdir(directory)) != NULL) { 26 | if (strcmp(position->d_name, ".") != 0 && 27 | strcmp(position->d_name, "..") != 0) 28 | printf("%s\n", position->d_name); 29 | if (errno != 0) { 30 | perror("READDIR"); 31 | strerror(errno); 32 | return 2; 33 | } 34 | } 35 | } else { 36 | perror("Something went wrong"); 37 | return 1; 38 | } 39 | 40 | /* TILL HERE */ 41 | 42 | closedir(directory); 43 | return (0); 44 | } -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/KolosEom/zad2(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | main: main.o 5 | 6 | clean: 7 | rm -f main.o main 8 | 9 | test: main 10 | @echo -e "\n\nTESTING\n\n" 11 | ./main 12 | 13 | all: main test 14 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/KolosEom/zad2(ok)/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | int main() { 11 | pid_t child; 12 | int status, retval; 13 | if ((child = fork()) < 0) { 14 | perror("fork"); 15 | exit(EXIT_FAILURE); 16 | } 17 | if (child == 0) { 18 | sleep(100); 19 | exit(EXIT_SUCCESS); 20 | } else { 21 | /* Proces macierzysty pobiera status zakończenie potomka child, 22 | * nie zawieszając swojej pracy. Jeśli proces się nie zakończył, wysyła 23 | * do dziecka sygnał SIGKILL. Jeśli wysłanie sygnału się nie powiodło, 24 | * ponownie oczekuje na zakończenie procesu child, tym razem zawieszając 25 | * pracę do czasu zakończenia sygnału jeśli się powiodło, wypisuje 26 | * komunikat sukcesu zakończenia procesu potomka z numerem jego PID i 27 | * statusem zakończenia. */ 28 | 29 | /* ADDED BY ME - FROM HERE */ 30 | 31 | waitpid(child, &status, WNOHANG); 32 | 33 | kill(child, SIGKILL); 34 | 35 | if (waitpid(child, &status, 0) != -1) { 36 | retval = WEXITSTATUS(status); 37 | printf("PID: %d, status: %d, return val: %d\n", getpid(), status, 38 | retval); 39 | } else { 40 | perror("WAITPID"); 41 | strerror(errno); 42 | } 43 | 44 | /* TILL HERE */ 45 | } 46 | exit(EXIT_SUCCESS); 47 | } 48 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/KolosEom/zad3(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | main: main.o 5 | 6 | clean: 7 | rm -f main.o main 8 | 9 | test: main 10 | @echo -e "\n\nTESTING\n\n" 11 | ./main -la 12 | 13 | all: main test 14 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/KolosEom/zad3(ok)/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char* argv[]) { 9 | int pdesk[2]; 10 | if (pipe(pdesk) == -1) { 11 | perror("PIPE"); 12 | return 1; 13 | } 14 | 15 | switch (fork()) { 16 | case -1: 17 | perror("FORK"); 18 | return 2; 19 | case 0: 20 | dup2(pdesk[1], STDOUT_FILENO); 21 | execvp("ls", argv); 22 | perror("EXECVP ls"); 23 | exit(1); 24 | default: { 25 | /* Zamknij deskryptor do zapisu, 26 | * skopiuj deskyptor końca do odczytu tego potoku na deskryptor 27 | * wejścia standardowego, wykonaj tr "a-z" "A-Z", w przypadku błędu 28 | * obsłuż go i wyjdź, zwracając 3. 29 | */ 30 | 31 | /* ADDED BY ME - FROM HERE */ 32 | 33 | close(pdesk[1]); 34 | 35 | dup2(pdesk[0], STDIN_FILENO); 36 | 37 | if (execlp("tr", "tr", "\"a-z\"", "\"A-Z\"", (char*)NULL) == -1) { 38 | perror("EXECLP tr"); 39 | strerror(errno); 40 | return 3; 41 | } 42 | 43 | /* TILL HERE */ 44 | } 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/KozlakSroda9:35/zad1(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | main: main.o 5 | 6 | clean: 7 | rm -f main.o main 8 | 9 | test: main 10 | @echo -e "\n\nTESTING\n\n" 11 | ./main "grep *" 12 | 13 | all: main test -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/KozlakSroda9:35/zad1(ok)/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | static void display_times(clock_t, struct tms*, struct tms*); 9 | 10 | static void do_cmd(char*, int instruction, int final); 11 | 12 | int main(int argc, char* argv[]) { 13 | int i; 14 | 15 | setbuf(stdout, NULL); 16 | for (i = 1; i < argc; i++) 17 | do_cmd(argv[i], i, argc - 1); 18 | exit(0); 19 | } 20 | 21 | static void do_cmd(char* cmd, 22 | int instruction, 23 | int final) /* wykonaj program, policz jego czasy, sprawdz, 24 | czy to nie jest ostatni program */ 25 | { 26 | struct tms tmsstart, tmsend; 27 | clock_t start, end; 28 | int status; 29 | 30 | printf("\ncommand: %s\n", cmd); 31 | 32 | /* CHANGES FROM HERE */ 33 | 34 | /*DO ZROBIENIA: zapamietaj czas w chwili aktualnej w zmiennych start i 35 | * tmsstart*/ 36 | 37 | if ((start = (times(&tmsstart))) == 38 | -1) /* zapamietaj wartosci poczatkowe pomiaru czasu*/ 39 | { 40 | printf("times error"); 41 | exit(-1); 42 | } 43 | 44 | if ((status = system(cmd)) < 0) /* wykonaj polecenie */ 45 | { 46 | printf("system() error"); 47 | exit(-1); 48 | } 49 | 50 | /*DO ZROBIENIA: zapamietaj czas w chwili aktualnej w zmiennych end i 51 | * tmsend*/ 52 | 53 | if ((end = (times(&tmsend))) == -1) /* zapamietaj wartosci koncowe */ 54 | { 55 | printf("times error"); 56 | exit(-1); 57 | } 58 | 59 | /* TILL HERE */ 60 | 61 | display_times(end - start, &tmsstart, &tmsend); 62 | 63 | if (instruction == final) 64 | exit(status); 65 | } 66 | 67 | static void display_times(clock_t real, 68 | struct tms* tmsstart, 69 | struct tms* tmsend) { 70 | static long clktck = 0; 71 | 72 | if (clktck == 0) /* sprawdz, czy stan zmiennej odczytywany pierwszy raz */ 73 | if ((clktck = sysconf(_SC_CLK_TCK)) < 0) { 74 | printf("sysconf error"); 75 | exit(-1); 76 | } 77 | 78 | printf(" real: %7.2f\n", real / (double)clktck); 79 | printf(" user: %7.2f\n", 80 | (tmsend->tms_utime - tmsstart->tms_utime) / (double)clktck); 81 | printf(" sys: %7.2f\n", 82 | (tmsend->tms_stime - tmsstart->tms_stime) / (double)clktck); 83 | printf(" child user: %7.2f\n", 84 | (tmsend->tms_cutime - tmsstart->tms_cutime) / (double)clktck); 85 | printf(" child sys: %7.2f\n", 86 | (tmsend->tms_cstime - tmsstart->tms_cstime) / (double)clktck); 87 | } -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/KozlakSroda9:35/zad2(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | main: main.o 5 | 6 | clean: 7 | rm -f main.o main 8 | 9 | test: main 10 | @echo -e "\n\nTESTING\n\n" 11 | ./main /home/jakub/CLionProjects/sysopy/tests/KozlakSroda9:35/zad2 /home/jakub/CLionProjects/sysopy/tests/KozlakSroda9:35/zad2/main.c 12 | 13 | all: main test -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/KozlakSroda9:35/zad2(ok)/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /* 6 | * 2. Program identyfikuje typy plików podane jako argumenty, 7 | * rozpoznaje zwykle pliki, katalogi oraz linki symboliczne. 8 | * Należy uzupełnić program w oznaczonych wierszach rozpoznając odpowiednie 9 | * rodzaje plików. (Trzy razy wywołać makro do sprawdzanie typu pliku z .st_mode 11 | */ 12 | 13 | int main(int argc, char* argv[]) { 14 | int i; 15 | struct stat buf; 16 | char* tekst; 17 | 18 | for (i = 1; i < argc; i++) { 19 | printf("%s: ", argv[i]); 20 | if (lstat(argv[i], &buf) < 0) { 21 | printf("lstat error"); 22 | continue; 23 | } 24 | 25 | /* CHANGES FROM HERE */ 26 | 27 | /* TU UZUPELNIC warunek rozpoznajacy zwykly plik*/ 28 | 29 | if (S_ISREG(buf.st_mode)) { // ADDED BY ME 30 | tekst = "zwykly plik"; 31 | } 32 | 33 | /* TU UZUPELNIC warunek rozpoznajacy katalog*/ 34 | 35 | else if (S_ISDIR(buf.st_mode)) { // ADDED BY ME 36 | tekst = "katalog"; 37 | } 38 | 39 | /* TU UZUPELNIC warunek rozpoznajacy link symboliczny*/ 40 | 41 | else if (S_ISLNK(buf.st_mode)) { // ADDED BY ME 42 | tekst = "link symboliczny"; 43 | } 44 | 45 | /* TILL HERE */ 46 | 47 | else { 48 | tekst = "**** cos innego !!! ****"; 49 | } 50 | 51 | printf("%s\n", tekst); 52 | } 53 | 54 | exit(0); 55 | } -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/KozlakSroda9:35/zad3(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | main: main.o 5 | 6 | clean: 7 | rm -f main.o main 8 | 9 | test: main 10 | @echo -e "\n\nTESTING\n\n" 11 | ./main 22 12 | ./main -9 13 | ./main 0 14 | ./main cos 15 | 16 | all: main test 17 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/KozlakSroda9:35/zad3(ok)/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | // 3. Obustronna komunikacja między dwoma procesami za pomocą 2 pipeów 8 | 9 | int main(int argc, char* argv[]) { 10 | if (argc != 2) { 11 | printf("Not a suitable number of program parameters\n"); 12 | exit(1); 13 | } 14 | 15 | int toChildFD[2]; 16 | int toParentFD[2]; 17 | 18 | pipe(toChildFD); 19 | pipe(toParentFD); 20 | 21 | int val1, val2, val3 = 0; 22 | 23 | pid_t pid; 24 | 25 | if ((pid = fork()) == 0) { 26 | /* CHANGES FROM HERE */ 27 | 28 | // odczytaj z potoku nienazwanego wartosc przekazana przez proces 29 | // macierzysty i zapisz w zmiennej val2 30 | 31 | read(toChildFD[0], &val2, sizeof(int)); // ADDED BY ME 32 | 33 | val2 = val2 * val2; 34 | 35 | // wyslij potokiem nienazwanym val2 do procesu macierzysego 36 | 37 | write(toParentFD[1], &val2, sizeof(int)); // ADDED BY ME 38 | 39 | } else { 40 | val1 = atoi(argv[1]); 41 | 42 | // wyslij val1 potokiem nienazwanym do priocesu potomnego 43 | 44 | write(toChildFD[1], &val1, sizeof(int)); // ADDED BY ME 45 | 46 | sleep(1); 47 | 48 | // odczytaj z potoku nienazwanego wartosc przekazana przez proces 49 | // potomny i zapisz w zmiennej val3 50 | 51 | read(toParentFD[0], &val3, sizeof(int)); // ADDED BY ME 52 | 53 | /* TILL HERE */ 54 | 55 | printf("%d square is: %d\n", val1, val3); 56 | } 57 | 58 | return 0; 59 | } -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/SiwikWtorek14:40/zad1(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | main: main.o 5 | 6 | clean: 7 | rm -f main.o main 8 | 9 | test: main 10 | @echo -e "\n\nTESTING\n\n" 11 | ./main 100 11 12 | ./main 100 10 13 | ./main 100 9 14 | 15 | all: main test 16 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/SiwikWtorek14:40/zad1(ok)/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | /* 7 | * 1. Ojciec wysyła dany sygnał wraz wartością z argv[2] 8 | * Dziecko blokuje wszystkie sygnały oprócz SIGUSR1, 9 | * oraz wypisuje wiadaomość którą dostał wraz z sygnałem. 10 | * sigqueue, siginfo itp. 11 | */ 12 | 13 | void sig_handler(int sig, siginfo_t* siginfo, void* context) { 14 | printf("Child: %d\n", siginfo->si_value.sival_int); 15 | } 16 | 17 | int main(int argc, char* argv[]) { 18 | if (argc != 3) { 19 | printf("Not a suitable number of program parameters\n"); 20 | return 1; 21 | } 22 | 23 | /* CHANGES FROM HERE */ 24 | 25 | struct sigaction action; 26 | 27 | action.sa_sigaction = &sig_handler; // takes three arguments, thus 28 | // sa_sigaction, not sa_handler 29 | action.sa_flags = SA_SIGINFO; // The signal handler takes three arguments, 30 | // not one - because of SA_SIGINFO 31 | 32 | sigemptyset(&action.sa_mask); 33 | 34 | sigset_t mask; 35 | 36 | if (sigfillset(&mask) == -1) { 37 | perror("SIGFILLSET problem"); 38 | } 39 | 40 | sigdelset(&mask, SIGUSR1); 41 | 42 | int child = fork(); 43 | 44 | if (child == 0) { 45 | // zablokuj wszystkie sygnaly za wyjatkiem SIGUSR1 46 | // zdefiniuj obsluge SIGUSR1 w taki sposob zeby proces potomny 47 | // wydrukowal na konsole przekazana przez rodzica wraz z sygnalem 48 | // SIGUSR1 wartosc 49 | 50 | sigprocmask(SIG_BLOCK, &mask, NULL); 51 | 52 | sigaction(SIGUSR1, &action, NULL); 53 | 54 | pause(); 55 | 56 | } else { 57 | // wyslij do procesu potomnego sygnal przekazany jako argv[2] 58 | // wraz z wartoscia przekazana jako argv[1] 59 | 60 | sleep(1); 61 | 62 | union sigval sv; 63 | sv.sival_int = atoi(argv[1]); 64 | 65 | int signal = atoi(argv[2]); 66 | 67 | sigqueue(child, signal, sv); 68 | } 69 | 70 | /* TILL HERE */ 71 | 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/SiwikWtorek14:40/zad2(ok) - to samo co KozlakSroda9:35zad3/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | main: main.o 5 | 6 | clean: 7 | rm -f main.o main 8 | 9 | test: main 10 | @echo -e "\n\nTESTING\n\n" 11 | ./main 22 12 | ./main -9 13 | ./main 0 14 | ./main cos 15 | 16 | all: main test 17 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/SiwikWtorek14:40/zad2(ok) - to samo co KozlakSroda9:35zad3/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | // 3. Obustronna komunikacja między dwoma procesami za pomocą 2 pipeów 8 | 9 | int main(int argc, char* argv[]) { 10 | if (argc != 2) { 11 | printf("Not a suitable number of program parameters\n"); 12 | exit(1); 13 | } 14 | 15 | int toChildFD[2]; 16 | int toParentFD[2]; 17 | 18 | pipe(toChildFD); 19 | pipe(toParentFD); 20 | 21 | int val1, val2, val3 = 0; 22 | 23 | pid_t pid; 24 | 25 | if ((pid = fork()) == 0) { 26 | /* CHANGES FROM HERE */ 27 | 28 | // odczytaj z potoku nienazwanego wartosc przekazana przez proces 29 | // macierzysty i zapisz w zmiennej val2 30 | 31 | read(toChildFD[0], &val2, sizeof(int)); // ADDED BY ME 32 | 33 | val2 = val2 * val2; 34 | 35 | // wyslij potokiem nienazwanym val2 do procesu macierzysego 36 | 37 | write(toParentFD[1], &val2, sizeof(int)); // ADDED BY ME 38 | 39 | } else { 40 | val1 = atoi(argv[1]); 41 | 42 | // wyslij val1 potokiem nienazwanym do priocesu potomnego 43 | 44 | write(toChildFD[1], &val1, sizeof(int)); // ADDED BY ME 45 | 46 | sleep(1); 47 | 48 | // odczytaj z potoku nienazwanego wartosc przekazana przez proces 49 | // potomny i zapisz w zmiennej val3 50 | 51 | read(toParentFD[0], &val3, sizeof(int)); // ADDED BY ME 52 | 53 | /* TILL HERE */ 54 | 55 | printf("%d square is: %d\n", val1, val3); 56 | } 57 | 58 | return 0; 59 | } -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/SiwikWtorek14:40/zad3(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | main: main.o 5 | 6 | clean: 7 | rm -f main.o main 8 | 9 | test: main 10 | @echo -e "\nTESTING\n" 11 | ./main 5 12 | ./main 7 13 | all: main test 14 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/SiwikWtorek14:40/zad3(ok)/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char* argv[]) { 6 | int i, pid; 7 | 8 | if (argc != 2) { 9 | printf("Not a suitable number of program arguments"); 10 | exit(2); 11 | } else { 12 | for (i = 0; i < atoi(argv[1]); i++) { 13 | //********************************************************* 14 | // Uzupelnij petle w taki sposob aby stworzyc dokladnie argv[1] 15 | // procesow potomnych, bedacych dziecmi tego samego procesu 16 | // macierzystego. Kazdy proces potomny powinien: 17 | // - "powiedziec ktorym jest dzieckiem", 18 | // - jaki ma pid, 19 | // - kto jest jego rodzicem 20 | //****************************************************** 21 | 22 | /* ADDED BY ME - FROM HERE */ 23 | 24 | pid = fork(); 25 | 26 | if (pid == 0) { 27 | printf( 28 | "I am child number %d, my pid is: %d, my parent's pid is: " 29 | "%d\n", 30 | i, getpid(), getppid()); 31 | break; 32 | } 33 | 34 | /* TILL HERE*/ 35 | } 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/kolospoprawkowyzforum/zad2(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | sender: sender.o 5 | 6 | receiver: receiver.o 7 | 8 | clean: 9 | rm -f sender.o sender receiver.o receiver squareFIFO 10 | 11 | test: sender receiver 12 | @echo -e "\nTESTING\n" 13 | ./sender 22 & 14 | ./receiver 15 | ./sender 9 & 16 | ./receiver 17 | ./sender -13 & 18 | ./receiver 19 | ./sender cos & 20 | ./receiver 21 | 22 | all: sender receiver 23 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/kolospoprawkowyzforum/zad2(ok)/receiver.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define PIPE "./squareFIFO" 9 | 10 | int main() { 11 | int val = 0; 12 | /*********************************** 13 | * odczytaj z potoku nazwanego PIPE zapisana tam wartosc i przypisz ja do 14 | *zmiennej val posprzataj 15 | ************************************/ 16 | 17 | /* FROM HERE */ 18 | 19 | int fd = open(PIPE, O_RDONLY); 20 | 21 | char buf[512]; 22 | 23 | read(fd, buf, sizeof(buf)); 24 | 25 | val = atoi(buf); 26 | 27 | close(fd); 28 | 29 | /* TILL HERE */ 30 | 31 | printf("%d square is: %d\n", val, val * val); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/kolospoprawkowyzforum/zad2(ok)/sender.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define PIPE "./squareFIFO" 9 | 10 | int main(int argc, char* argv[]) { 11 | if (argc != 2) { 12 | printf("Not a suitable number of program parameters\n"); 13 | return (1); 14 | } 15 | 16 | // utworz potok nazwany pod sciezka reprezentowana przez PIPE 17 | // zakladajac ze parametrem wywolania programu jest liczba calkowita 18 | // zapisz te wartosc jako int do potoku i posprzataj 19 | 20 | /* FROM HERE */ 21 | 22 | mkfifo(PIPE, 0777); 23 | 24 | int fd = open(PIPE, O_WRONLY); 25 | 26 | char buf[512]; 27 | char* parameter = argv[1]; 28 | 29 | snprintf(buf, sizeof(buf), "%s", parameter); 30 | 31 | write(fd, buf, sizeof(buf)); 32 | 33 | close(fd); 34 | 35 | /* TILL HERE */ 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/kolospoprawkowyzforum/zad3(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | main: main.o 5 | 6 | clean: 7 | rm -f main.o main 8 | 9 | test: main 10 | @echo -e "\n\nTESTING\n\n" 11 | ./main 100 11 12 | ./main 100 10 13 | ./main 100 9 14 | 15 | all: main test 16 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_1/kolospoprawkowyzforum/zad3(ok)/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void sig_handler(int sig, siginfo_t* siginfo, void* context) { 7 | printf("Value from sigval %d\n", siginfo->si_value.sival_int); 8 | } 9 | 10 | int main(int argc, char* argv[]) { 11 | if (argc != 3) { 12 | printf("Not a suitable number of program parameters\n"); 13 | return 1; 14 | } 15 | 16 | struct sigaction action; 17 | 18 | action.sa_sigaction = &sig_handler; 19 | action.sa_flags = SA_SIGINFO; 20 | 21 | sigset_t mask; 22 | 23 | sigemptyset(&action.sa_mask); 24 | 25 | sigfillset(&mask); 26 | 27 | int child = fork(); 28 | if (child == 0) { 29 | // zablokuj wszystkie sygnaly za wyjatkiem SIGUSR1 30 | // zdefiniuj obsluge SIGUSR1 w taki sposob zeby proces potomny 31 | // wydrukowal na konsole przekazana przez rodzica wraz z sygnalem 32 | // SIGUSR1 wartosc 33 | 34 | sigdelset(&mask, SIGUSR1); 35 | 36 | sigprocmask(SIG_BLOCK, &mask, NULL); 37 | 38 | sigaction(SIGUSR1, &action, NULL); 39 | 40 | pause(); 41 | 42 | } else { 43 | // wyslij do procesu potomnego sygnal przekazany jako argv[2] 44 | // wraz z wartoscia przekazana jako argv[1] 45 | 46 | sleep(1); 47 | 48 | int signal = atoi(argv[2]); 49 | 50 | int value = atoi(argv[1]); 51 | 52 | union sigval sigval; 53 | sigval.sival_int = value; 54 | 55 | sigqueue(child, signal, sigval); 56 | } 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/EOM(ok)/zad1(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | main: main.c 5 | $(CC) $^ -o $@ $(CFLAGS) 6 | clean: 7 | rm -f main.o main 8 | 9 | test: main 10 | @echo -e "\n\nTESTING\n\n" 11 | ./main 12 | ipcs -m 13 | all: main test 14 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/EOM(ok)/zad1(ok)/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define MAX 20 8 | #define KEY "./path" 9 | 10 | int main() { 11 | int shm_id, i; 12 | int* buf; 13 | 14 | // Wygeneruj klucz dla kolejki na podstawie KEYi znaku 'a' 15 | 16 | /** ADDED BY ME FROM HERE **/ 17 | 18 | int key = ftok(KEY, 'a'); 19 | 20 | /** TILL HERE **/ 21 | 22 | // Utwórz segment pamięci współdzielonej shmid o prawach dostępu 600, 23 | // rozmiarze MAX jeśli segment już istnieje, zwróć błąd, jeśli utworzenie 24 | // pamięci się nie powiedzie zwróć błąd i wartość 1 25 | 26 | /** ADDED BY ME FROM HERE **/ 27 | 28 | shm_id = shmget(key, MAX, IPC_CREAT | 0600); 29 | if (shm_id == -1) { 30 | printf("shmget error\n"); 31 | return 1; 32 | } 33 | 34 | /** TILL HERE **/ 35 | 36 | // Przyłącz segment pamięci współdzielonej do procesu do buf, obsłuż błędy i 37 | // zwróć 1 38 | 39 | /** ADDED BY ME FROM HERE **/ 40 | 41 | buf = shmat(shm_id, NULL, 0); 42 | if (buf == (void*)-1) { 43 | printf("shmat error\n"); 44 | return 1; 45 | } 46 | 47 | /** TILL HERE **/ 48 | 49 | for (i = 0; i < MAX; i++) { 50 | buf[i] = i * i; 51 | printf("Wartość: %d \n", buf[i]); 52 | } 53 | 54 | printf("Memory written\n"); 55 | 56 | // odłącz i usuń segment pamięci współdzielonej 57 | 58 | /** ADDED BY ME FROM HERE **/ 59 | 60 | shmdt(buf); 61 | shmctl(shm_id, IPC_RMID, NULL); 62 | 63 | /** TILL HERE **/ 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/EOM(ok)/zad2(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -lpthread 2 | CC = gcc 3 | 4 | main: main.c 5 | $(CC) $^ -o $@ $(CFLAGS) 6 | 7 | clean: 8 | rm -f main.o main 9 | 10 | test: main 11 | @echo -e "\nTEST\n" 12 | ./main 2 5 4 13 | ./main 0 5 4 14 | 15 | all: main 16 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/EOM(ok)/zad3(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -std=c99 -lpthread 2 | CC = gcc 3 | 4 | main: main.c 5 | $(CC) $^ -o $@ $(CFLAGS) 6 | clean: 7 | rm -f main.o main 8 | 9 | test: main 10 | @echo -e "\n\nTESTING\n\n" 11 | ./main 12 | all: main test 13 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/EOM(ok)/zad3(ok)/main.c: -------------------------------------------------------------------------------- 1 | #define _BSD_SOURCE 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define THREADS_NR 9 8 | 9 | void* hello(void* arg) { 10 | // Napisz funkcję wypisującą komunikat typu Hello (wartość_TID): 11 | // (numer_TID) 12 | // i zwracającą status o wartości równej agrumentowi przesłanemu do funkcji 13 | 14 | /** ADDED BY ME FROM HERE **/ 15 | 16 | printf("Hello\tTID %ld\targ: %d\n", pthread_self(), *(int*)arg); 17 | 18 | /** TILL HERE **/ 19 | 20 | // koniec 21 | 22 | pthread_exit(*(int*)arg); 23 | } 24 | 25 | int main(int argc, char* argv[]) { 26 | pthread_t hello_threads[THREADS_NR]; 27 | int* count = malloc(sizeof(int)); 28 | int i; 29 | 30 | for (i = 0; i < THREADS_NR; i++) { 31 | *count = i + 1; 32 | 33 | int result = 34 | pthread_create(&hello_threads[i], NULL, hello, (void*)count); 35 | if (result != 0) { 36 | perror("Could not create thread."); 37 | } 38 | 39 | usleep(1000); 40 | } 41 | 42 | int* hello_results[THREADS_NR]; 43 | 44 | // Czekaj na zakończenie THREADS_NR wątków, pobierz status zakończeńczenia, 45 | // zapisz go w hello_result i wypisz na ekran: Thread (indeks wątku+1) TID: 46 | // (nr_TID) returned value: (status zakonczenia watku) 47 | 48 | /** ADDED BY ME FROM HERE **/ 49 | 50 | for (i = 0; i < THREADS_NR; i++) { 51 | void* ret_val; 52 | 53 | pthread_join(hello_threads[i], &ret_val); 54 | 55 | hello_results[i] = (int*)ret_val; 56 | } 57 | 58 | for (i = 0; i < THREADS_NR; i++) { 59 | printf("Thread\t%d TID: %ld\tretval: %d\n", i + 1, hello_threads[i], 60 | hello_results[i]); 61 | } 62 | 63 | /** TILL HERE **/ 64 | 65 | // koniec 66 | free(count); 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/JK(ok)/zad1(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc -pthread 3 | 4 | main: zad1.o 5 | 6 | clean: 7 | rm -f ./zad1.o ./zad1 8 | 9 | test: zad1 10 | @echo -e "\n\nTESTING\n\n" 11 | ./zad1 4 3 2 12 | @echo -e "====================================================================\n\n" 13 | ./zad1 5 5 14 | @echo -e "====================================================================\n\n" 15 | ./zad1 1 1 1 1 1 16 | all: zad1 test 17 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/JK(ok)/zad2(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | main: zad2.o 5 | 6 | clean: 7 | rm -f ./zad2.o ./zad2 8 | 9 | test: zad2 10 | @echo -e "\n\nTESTING\n\n" 11 | ./zad2 good 12 | @echo -e "==========================================================" 13 | ./zad2 bad 14 | 15 | all: zad2 test 16 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/JK(ok)/zad2(ok)/zad2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #define BUF_SIZE 1000 11 | 12 | union semun { /* Uzywane do semctl() */ 13 | int val; 14 | struct semid_ds* buf; 15 | unsigned short* array; 16 | struct seminfo* __buf; 17 | }; 18 | 19 | typedef enum { FALSE, TRUE } Boolean; 20 | 21 | Boolean bsUseSemUndo = FALSE; 22 | Boolean bsRetryOnEintr = TRUE; 23 | 24 | int /* Inicjalizacja dostepnego semafora*/ 25 | initSemAvailable(int semId, int semNum) { 26 | union semun arg; 27 | 28 | arg.val = 1; 29 | return semctl(semId, semNum, SETVAL, arg); 30 | } 31 | 32 | int /* Inicjalizacja zajetego semafora */ 33 | initSemInUse(int semId, int semNum) { 34 | union semun arg; 35 | 36 | arg.val = 0; 37 | return semctl(semId, semNum, SETVAL, arg); 38 | } 39 | 40 | /* Operacja P*/ 41 | 42 | int reserveSem(int semId, int semNum) { 43 | struct sembuf sops; 44 | 45 | /* Ustaw odpowiednie pola struktury sops i wykonaj 46 | operacje na semaforze semid*/ 47 | 48 | /** ADDED BY ME FROM HERE **/ 49 | 50 | sops.sem_num = semNum; 51 | sops.sem_flg = 0; 52 | sops.sem_op = -1; 53 | 54 | return semop(semId, &sops, 1); 55 | 56 | /** TILL HERE **/ 57 | } 58 | 59 | int /* Operacja V */ 60 | releaseSem(int semId, int semNum) { 61 | struct sembuf sops; 62 | 63 | /* Ustaw odpowiednie pola struktury sops i wykonaj 64 | operacje na semaforze semid*/ 65 | 66 | /** ADDED BY ME FROM HERE **/ 67 | 68 | sops.sem_num = semNum; 69 | sops.sem_flg = 0; 70 | sops.sem_op = 1; 71 | 72 | return semop(semId, &sops, 1); 73 | 74 | /** TILL HERE **/ 75 | } 76 | 77 | int main(int argc, char* argv[]) { 78 | int semId = 1; 79 | int s; 80 | 81 | if (argc < 2 || argc > 3 || strcmp(argv[1], "--help") == 0) { 82 | printf("%s good OR %s bad\n", argv[0], argv[0]); 83 | exit(-1); 84 | } 85 | 86 | semId = semget(IPC_PRIVATE, 1, S_IRUSR | S_IWUSR); 87 | 88 | if (strcmp(argv[1], "good") == 0) { 89 | s = initSemAvailable(semId, 0); 90 | 91 | s = reserveSem(semId, 0); 92 | printf("Sekcja krytyczna! \n"); 93 | s = releaseSem(semId, 0); 94 | 95 | } else if (strcmp(argv[1], "bad") == 0) { 96 | s = initSemInUse(semId, 0); 97 | 98 | s = reserveSem(semId, 0); 99 | printf("Sekcja krytyczna! \n"); 100 | s = releaseSem(semId, 0); 101 | } else { 102 | printf("Argument error \n"); 103 | exit(-1); 104 | } 105 | 106 | exit(EXIT_SUCCESS); 107 | } 108 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/JK(ok)/zad3(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | main: main.o 5 | 6 | clean: 7 | rm -f main.o main 8 | 9 | test: main 10 | @echo -e "\nTESTING\n" 11 | @rm -f ./us 12 | ./main ./us 13 | @ls -l ./us 14 | @rm -f ./us 15 | 16 | all: main test 17 | 18 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/JK(ok)/zad3(ok)/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | /* 10 | * Funkcja 'uname' przyjmuje socket domeny unix ('s') i jego 11 | * docelowa nazwe ('name'). Funkcja 'uname' powinna: 12 | * - nadac socketowi 's' nazwe 'name', 13 | * - zwrocic 0 w przypadku powodzenia i -1 w przypadku bledu. 14 | */ 15 | int uname(int s, char* name) { 16 | // Uzupelnij cialo funkcji uname zgodnie z 17 | // komentarzem powyzej. 18 | 19 | /** ADDED BY ME FROM HERE **/ 20 | 21 | struct sockaddr_un sock; 22 | 23 | sock.sun_family = AF_UNIX; 24 | strcpy(sock.sun_path, name); 25 | 26 | return bind(s, (struct sockaddr*)&sock, sizeof(struct sockaddr_un)); 27 | 28 | /** TILL HERE **/ 29 | } 30 | 31 | /* 32 | * Funkcja 'uconnect' przyjmuje socket domeny unix ('s') i jego 33 | * docelowy adres ('name'). Funkcja 'uconnect' powinna: 34 | * - polaczyc socket 's' z adresem 'name', 35 | * - zwrocic 0 w przypadku powodzenia i -1 w przypadku bledu. 36 | */ 37 | int uconnect(int s, char* name) { 38 | // Uzupelnij cialo funkcji uconnect zgodnie z 39 | // komentarzem powyzej 40 | 41 | /** ADDED BY ME FROM HERE **/ 42 | 43 | struct sockaddr_un sock; 44 | 45 | sock.sun_family = AF_UNIX; 46 | strcpy(sock.sun_path, name); 47 | 48 | return connect(s, (struct sockaddr*)&sock, sizeof(struct sockaddr_un)); 49 | 50 | /** TILL HERE **/ 51 | } 52 | 53 | int main(int argc, char* argv[]) { 54 | if (argc < 2) 55 | return -1; 56 | 57 | if (fork() > 0) { 58 | char buf[4]; 59 | 60 | int s = socket(AF_UNIX, SOCK_STREAM, 0); 61 | 62 | if (uname(s, argv[1]) || listen(s, 1)) 63 | return -1; 64 | 65 | int fd = accept(s, NULL, 0); 66 | 67 | read(fd, buf, 4); 68 | 69 | printf("%4s\n", buf); 70 | 71 | } else { 72 | char buf[4]; 73 | 74 | int i; 75 | 76 | for (i = 0; i < 4; i++) 77 | buf[i] = (rand() % 26 + 'b'); 78 | 79 | int c = socket(AF_UNIX, SOCK_STREAM, 0); 80 | 81 | sleep(1); 82 | 83 | if (uconnect(c, argv[1])) 84 | return -1; 85 | 86 | write(c, buf, 4); 87 | } 88 | 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/S_1(ok)/zad1(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -std=c99 -lpthread 2 | CC = gcc 3 | 4 | main: main.c 5 | $(CC) $^ -o $@ $(CFLAGS) 6 | 7 | clean: 8 | rm -f main.o main 9 | 10 | test: main 11 | @echo -e "\nTEST\n" 12 | ./main 3 3 13 | 14 | all: main 15 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/S_1(ok)/zad1(ok)/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void* hello(void* arg) { 10 | sleep(1); 11 | while (1) { 12 | printf("Hello world from thread number %d\n", *(int*)arg); 13 | /**************************************************** 14 | przerwij dzialanie watku jesli bylo takie zadanie 15 | *****************************************************/ 16 | 17 | /****************************************************/ 18 | 19 | /** ??? PROBABLY NOTHING SHOULD BE PLACED IN HERE **/ 20 | 21 | /****************************************************/ 22 | 23 | printf("Hello again world from thread number %d\n", *(int*)arg); 24 | sleep(2); 25 | } 26 | 27 | return NULL; 28 | } 29 | 30 | int main(int argc, char** args) { 31 | if (argc != 3) { 32 | printf("Not a suitable number of program parameters\n"); 33 | return (1); 34 | } 35 | 36 | int n = atoi(args[1]); 37 | 38 | /************************************************** 39 | Utworz n watkow realizujacych funkcje hello 40 | **************************************************/ 41 | 42 | /** ADDED BY ME FROM HERE **/ 43 | 44 | pthread_t* threads = malloc(sizeof(pthread_t) * n); 45 | 46 | int* ids = malloc(sizeof(int) * n); 47 | 48 | for (int i = 0; i < n; ++i) { 49 | ids[i] = i; 50 | pthread_create(&threads[i], NULL, hello, &ids[i]); 51 | } 52 | 53 | /** TILL HERE **/ 54 | 55 | int i = 0; 56 | while (i++ < atoi(args[2])) { 57 | printf("Hello from main %d\n", i); 58 | sleep(2); 59 | } 60 | 61 | i = 0; 62 | 63 | /******************************************* 64 | "Skasuj" wszystke uruchomione watki i poczekaj na ich zakonczenie 65 | *******************************************/ 66 | 67 | /** ADDED BY ME FROM HERE **/ 68 | 69 | for (int i = 0; i < n; ++i) { 70 | pthread_cancel(threads[i]); 71 | } 72 | 73 | for (int i = 0; i < n; ++i) { 74 | pthread_join(threads[i], (void**)NULL); 75 | } 76 | 77 | /** TILL HERE **/ 78 | 79 | printf("DONE"); 80 | 81 | return 0; 82 | } 83 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/S_1(ok)/zad2(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -lrt 2 | CC = gcc 3 | 4 | sender: sender.c 5 | $(CC) $^ -o $@ $(CFLAGS) 6 | 7 | receiver: receiver.c 8 | $(CC) $^ -o $@ $(CFLAGS) 9 | 10 | clean: 11 | rm -f sender.o sender receiver.o receiver 12 | 13 | test: sender receiver 14 | @echo -e "\nTESTING\n" 15 | ./sender 22 & 16 | ./receiver 17 | ./sender 9 & 18 | ./receiver 19 | ./sender -13 & 20 | ./receiver 21 | ./sender cos & 22 | ./receiver 23 | all: sender receiver 24 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/S_1(ok)/zad2(ok)/receiver.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define SHM_NAME "/kol_shm" 11 | #define MAX_SIZE 1024 12 | 13 | int main(int argc, char** argv) { 14 | sleep(1); 15 | int val = 0; 16 | /******************************************* 17 | Utworz/otworz posixowy obszar pamieci wspolnej "reprezentowany" przez 18 | SHM_NAME odczytaj zapisana tam wartosc i przypisz ja do zmiennej val 19 | posprzataj 20 | *********************************************/ 21 | 22 | /** ADDED BY ME FROM HERE **/ 23 | 24 | int fd = shm_open(SHM_NAME, O_RDWR, 0666); 25 | 26 | char* addr = 27 | (char*)mmap(NULL, MAX_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 28 | 29 | val = atoi(addr); 30 | 31 | munmap(addr, MAX_SIZE); 32 | 33 | /** not told to clean up ?? */ 34 | 35 | /** TILL HERE **/ 36 | 37 | printf("%d square is: %d \n", val, val * val); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/S_1(ok)/zad2(ok)/sender.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define SHM_NAME "/kol_shm" 11 | #define MAX_SIZE 1024 12 | 13 | int main(int argc, char** argv) { 14 | if (argc != 2) { 15 | printf("Not a suitable number of program parameters\n"); 16 | return (1); 17 | } 18 | 19 | /*************************************** 20 | Utworz/otworz posixowy obszar pamieci wspolnej "reprezentowany" przez 21 | SHM_NAME zapisz tam wartosc przekazana jako parametr wywolania programu 22 | posprzataj 23 | *****************************************/ 24 | 25 | /** ADDED BY ME FROM HERE **/ 26 | 27 | int fd = shm_open(SHM_NAME, O_RDWR | O_CREAT, 0666); 28 | 29 | ftruncate(fd, MAX_SIZE); 30 | 31 | char* addr = 32 | (char*)mmap(NULL, MAX_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 33 | 34 | addr[0] = '\0'; 35 | 36 | strncpy(addr, argv[1], MAX_SIZE); 37 | 38 | munmap(addr, MAX_SIZE); 39 | 40 | /** not told to clean up ?? */ 41 | 42 | /** TILL HERE **/ 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/S_1(ok)/zad3(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | main: main.c 5 | $(CC) $^ -o $@ $(CFLAGS) 6 | 7 | clean: 8 | rm -f main.o main 9 | 10 | test: main 11 | @echo -e "\nTEST\n" 12 | ./main 2 5 4 13 | ./main 0 5 4 14 | 15 | all: main 16 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/S_2(ok)/zad1(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -lpthread 2 | CC = gcc 3 | 4 | main: main.c 5 | $(CC) $^ -o $@ $(CFLAGS) 6 | 7 | clean: 8 | rm -f main.o main 9 | 10 | test: main 11 | @echo -e "\nTEST\n" 12 | ./main 2 5 4 13 | ./main 0 5 4 14 | 15 | all: main 16 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/S_2(ok)/zad2(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -lrt 2 | CC = gcc 3 | 4 | sender: sender.c 5 | $(CC) $^ -o $@ $(CFLAGS) 6 | 7 | receiver: receiver.c 8 | $(CC) $^ -o $@ $(CFLAGS) 9 | 10 | clean: 11 | rm -f sender.o sender receiver.o receiver 12 | 13 | test: sender receiver 14 | @echo -e "\nTESTING\n" 15 | ./receiver & 16 | ./sender 22 17 | ./receiver & 18 | ./sender 9 19 | ./receiver & 20 | ./sender -13 21 | ./receiver & 22 | ./sender cos 23 | all: sender receiver 24 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/S_2(ok)/zad2(ok)/receiver.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define UNIX_PATH_MAX 108 10 | #define SOCK_PATH "sock_path" 11 | 12 | int main() { 13 | int fd = -1; 14 | 15 | /********************************************* 16 | Utworz socket domeny unixowej typu datagramowego 17 | Utworz strukture adresowa ustawiajac adres/sciezke komunikacji na SOCK_PATH 18 | Zbinduj socket z adresem/sciezka SOCK_PATH 19 | **********************************************/ 20 | 21 | /** ADDED BY ME FROM HERE **/ 22 | 23 | fd = socket(AF_UNIX, SOCK_DGRAM, 0); 24 | 25 | struct sockaddr_un addr; 26 | 27 | addr.sun_family = AF_UNIX; 28 | addr.sun_path[0] = '\0'; 29 | 30 | strncpy(addr.sun_path, SOCK_PATH, UNIX_PATH_MAX); 31 | 32 | bind(fd, (const struct sockaddr*)&addr, sizeof(struct sockaddr_un)); 33 | 34 | /** TILL HERE **/ 35 | 36 | char buf[20]; 37 | if (read(fd, buf, 20) == -1) 38 | perror("Error receiving message"); 39 | int val = atoi(buf); 40 | printf("%d square is: %d\n", val, val * val); 41 | 42 | /*************************** 43 | Posprzataj po sockecie 44 | ****************************/ 45 | 46 | /** ADDED BY ME FROM HERE **/ 47 | 48 | shutdown(fd, SHUT_RDWR); 49 | close(fd); 50 | unlink(SOCK_PATH); 51 | 52 | /** TILL HERE **/ 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/S_2(ok)/zad2(ok)/sender.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define UNIX_PATH_MAX 108 9 | #define SOCK_PATH "sock_path" 10 | 11 | int main(int argc, char* argv[]) { 12 | if (argc != 2) { 13 | printf("Not a suitable number of program parameters\n"); 14 | return (1); 15 | } 16 | sleep(1); 17 | 18 | /********************************************* 19 | Utworz socket domeny unixowej typu datagramowego 20 | Utworz strukture adresowa ustawiajac adres/sciezke komunikacji na SOCK_PATH 21 | Polacz sie korzystajac ze zdefiniowanych socketu i struktury adresowej 22 | ***********************************************/ 23 | int fd = -1; 24 | 25 | /** ADDED BY ME FROM HERE **/ 26 | 27 | fd = socket(AF_UNIX, SOCK_DGRAM, 0); 28 | 29 | struct sockaddr_un addr; 30 | 31 | addr.sun_family = AF_UNIX; 32 | addr.sun_path[0] = '\0'; 33 | 34 | strncpy(addr.sun_path, SOCK_PATH, UNIX_PATH_MAX); 35 | 36 | connect(fd, (const struct sockaddr*)&addr, sizeof(struct sockaddr_un)); 37 | 38 | /** TILL HERE **/ 39 | 40 | char buff[20]; 41 | int to_send = sprintf(buff, argv[1]); 42 | 43 | if (write(fd, buff, to_send + 1) == -1) { 44 | perror("Error sending msg to server"); 45 | } 46 | 47 | /***************************** 48 | posprzataj po sockecie 49 | ********************************/ 50 | 51 | close(fd); 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/S_2(ok)/zad3(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | sender: sender.o 5 | 6 | receiver: receiver.o 7 | 8 | clean: 9 | rm -f sender.o sender receiver.o receiver squareFIFO 10 | 11 | test: sender receiver 12 | @echo -e "\nTESTING\n" 13 | ipcs -q 14 | ./sender 22 & 15 | ipcs -q 16 | ./receiver 17 | ipcs -q 18 | ./sender 9 & 19 | ipcs -q 20 | ./receiver 21 | ipcs -q 22 | ./sender -13 & 23 | ipcs -q 24 | ./receiver 25 | ipcs -q 26 | ./sender cos & 27 | ipcs -q 28 | ./receiver 29 | ipcs -q 30 | all: sender receiver 31 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/S_2(ok)/zad3(ok)/receiver.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | /** path must be an existing one **/ 10 | 11 | #define KEY "/tmp" 12 | 13 | int main() { 14 | sleep(1); 15 | int val = 0; 16 | 17 | /********************************** 18 | Otworz kolejke systemu V "reprezentowana" przez KEY 19 | **********************************/ 20 | 21 | /** ADDED BY ME FROM HERE **/ 22 | 23 | key_t key = ftok(KEY, 1); 24 | 25 | int queue = msgget(key, IPC_CREAT | 0666); 26 | if (queue < 0) { 27 | perror("msgget"); 28 | exit(1); 29 | } 30 | 31 | /** TILL HERE **/ 32 | 33 | while (1) { 34 | /********************************** 35 | Odczytaj zapisane w kolejce wartosci i przypisz je do zmiennej val 36 | obowiazuja funkcje systemu V 37 | ************************************/ 38 | 39 | /** ADDED BY ME FROM HERE **/ 40 | 41 | if (msgrcv(queue, &val, sizeof(val), 0, 0) <= 0) { 42 | perror("Could not receive message"); 43 | exit(1); 44 | } 45 | 46 | /** TILL HERE **/ 47 | 48 | printf("%d square is: %d\n", val, val * val); 49 | } 50 | 51 | /******************************* 52 | posprzataj 53 | ********************************/ 54 | 55 | msgctl(queue, IPC_RMID, NULL); 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_17_18/test_2/S_2(ok)/zad3(ok)/sender.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | /** path must be an existing one **/ 8 | 9 | #define KEY "/tmp" 10 | 11 | int main(int argc, char* argv[]) { 12 | if (argc != 2) { 13 | printf("Not a suitable number of program parameters\n"); 14 | return (1); 15 | } 16 | 17 | /****************************************************** 18 | Utworz kolejke komunikatow systemu V "reprezentowana" przez KEY 19 | Wyslij do niej wartosc przekazana jako parametr wywolania programu 20 | Obowiazuja funkcje systemu V 21 | ******************************************************/ 22 | 23 | /** ADDED BY ME FROM HERE **/ 24 | 25 | key_t key = ftok(KEY, 1); 26 | 27 | int value = atoi(argv[1]); 28 | 29 | int queue = msgget(key, IPC_CREAT | 0666); 30 | 31 | if (msgsnd(queue, &value, sizeof(int), 0) < 0) { 32 | perror("Problem with msgsnd"); 33 | exit(1); 34 | } 35 | 36 | /** TILL HERE **/ 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_18_19/mytest_1/Readme.md: -------------------------------------------------------------------------------- 1 | ### my first test 18_19 2 | 3 | I could not get files from moodle after the test so I changed 4 | previous tests a bit in order to make it look exactly like the test I took 5 | 6 | Everything works fine -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_18_19/mytest_1/zad1(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | main: main.o 5 | 6 | clean: 7 | rm -f main.o main 8 | 9 | test: main 10 | @echo -e "\n\nTESTING\n\n" 11 | ./main /home/jakub/CLionProjects/sysopy 12 | 13 | all: main test -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_18_19/mytest_1/zad1(ok)/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char* argv[]) { 7 | DIR* directory; 8 | if (argc != 2) { 9 | printf("Call %s path", argv[0]); 10 | return 1; 11 | } 12 | struct dirent* position; 13 | 14 | /* 15 | * Otwórz katalog, w przypadku błędu otwarcia zwróć błąd funkcji 16 | otwierającej i wartość 1. Wyświetl zawartość katalogu katalog, pomijając 17 | "." i ".." Jeśli podczas tej operacji wartość errno zostanie ustawiona, 18 | zwróć błąd funkcji czytającej oraz wartość 2*/ 19 | 20 | /* ADDED BY ME - FROM HERE */ 21 | 22 | char* directory_path = argv[1]; 23 | 24 | if ((directory = opendir(directory_path)) != NULL) { 25 | while ((position = readdir(directory)) != NULL) { 26 | if (strcmp(position->d_name, ".") != 0 && 27 | strcmp(position->d_name, "..") != 0) 28 | printf("%s\n", position->d_name); 29 | if (errno != 0) { 30 | perror("READDIR"); 31 | strerror(errno); 32 | return 2; 33 | } 34 | } 35 | } else { 36 | perror("Something went wrong"); 37 | return 1; 38 | } 39 | 40 | /* TILL HERE */ 41 | 42 | closedir(directory); 43 | return (0); 44 | } -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_18_19/mytest_1/zad2(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | main: main.o 5 | 6 | clean: 7 | rm -f main.o main 8 | 9 | test: main 10 | @echo -e "\n\nTESTING\n\n" 11 | ./main 5 12 | 13 | all: main test 14 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_18_19/mytest_1/zad2(ok)/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | // one change comparing to previous year 11 | 12 | int main(int argc, char** argv) { 13 | if (argc != 2) { 14 | printf("WRONG NUMBER OF ARGUMENTS"); 15 | return -1; 16 | } 17 | 18 | pid_t child; 19 | int status, retval; 20 | if ((child = fork()) < 0) { 21 | perror("fork"); 22 | exit(EXIT_FAILURE); 23 | } 24 | if (child == 0) { 25 | sleep(100); 26 | exit(EXIT_SUCCESS); 27 | } else { 28 | /* Proces macierzysty pobiera status zakończenie potomka child, nie 29 | * zawieszając swojej pracy. Proces spi tyle ile podane w argumencie 30 | * Jeśli proces się nie zakończył, wysyła do dziecka sygnał SIGKILL / 31 | * SIGTERM - ktorys z tych mozna bylo Jeśli wysłanie sygnału się nie 32 | * powiodło, ponownie oczekuje na zakończenie procesu child, tym razem 33 | * zawieszając pracę do czasu zakończenia sygnału jeśli się powiodło, 34 | * wypisuje komunikat sukcesu zakończenia procesu potomka z numerem jego 35 | * PID i statusem zakończenia. CZYLI jedyna zmiana byl sleep z argv[1] 36 | * */ 37 | 38 | /* ADDED BY ME - FROM HERE */ 39 | 40 | char* sec = argv[1]; 41 | int seconds = atoi(sec); 42 | 43 | sleep(seconds); 44 | 45 | waitpid(child, &status, WNOHANG); 46 | 47 | kill(child, SIGKILL); 48 | 49 | if (waitpid(child, &status, 0) != -1) { 50 | retval = WEXITSTATUS(status); 51 | printf("PID: %d, status: %d, return val: %d\n", getpid(), status, 52 | retval); 53 | } else { 54 | perror("WAITPID"); 55 | strerror(errno); 56 | } 57 | 58 | /* TILL HERE */ 59 | } 60 | exit(EXIT_SUCCESS); 61 | } 62 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_18_19/mytest_1/zad3(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | main: main.o 5 | 6 | clean: 7 | rm -f main.o main 8 | 9 | test: main 10 | @echo -e "\n\nTESTING\n\n" 11 | ./main -la 12 | 13 | all: main test 14 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_18_19/mytest_1/zad3(ok)/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char* argv[]) { 9 | int pdesk[2]; 10 | if (pipe(pdesk) == -1) { 11 | perror("PIPE"); 12 | return 1; 13 | } 14 | 15 | switch (fork()) { 16 | case -1: 17 | perror("FORK"); 18 | return 2; 19 | case 0: 20 | dup2(pdesk[1], STDOUT_FILENO); 21 | execvp("ls", argv); 22 | perror("EXECVP ls"); 23 | exit(1); 24 | default: { 25 | /* Zamknij deskryptor do zapisu, 26 | * skopiuj deskyptor końca do odczytu tego potoku na deskryptor 27 | * wejścia standardowego, wykonaj tr "a-z" "A-Z", w przypadku błędu 28 | * obsłuż go i wyjdź, zwracając 3. 29 | */ 30 | 31 | /* ADDED BY ME - FROM HERE */ 32 | 33 | close(pdesk[1]); 34 | 35 | dup2(pdesk[0], STDIN_FILENO); 36 | 37 | if (execlp("tr", "tr", "\"a-z\"", "\"A-Z\"", (char*)NULL) == -1) { 38 | perror("EXECLP tr"); 39 | strerror(errno); 40 | return 3; 41 | } 42 | 43 | /* TILL HERE */ 44 | } 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_18_19/mytest_2/Readme.md: -------------------------------------------------------------------------------- 1 | ### my second test 18_19 2 | 3 | Everything works fine -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_18_19/mytest_2/zad1(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall 2 | CC = gcc 3 | 4 | main: main.c 5 | $(CC) $^ -o $@ $(CFLAGS) 6 | clean: 7 | rm -f main.o main 8 | 9 | test: main 10 | @echo -e "\n\nTESTING\n\n" 11 | ./main 12 | ipcs -m 13 | all: main test 14 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_18_19/mytest_2/zad1(ok)/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define MAX 20 8 | #define KEY "./path" 9 | 10 | int main() { 11 | int shmid, i; 12 | int* buf; 13 | // Wygeneruj klucz dla kolejki na podstawie KEYi znaku 'a' 14 | 15 | // Utwórz segment pamięci współdzielonej shmid o prawach dostępu 600, 16 | // rozmiarze MAX jeśli segment już istnieje, zwróć błąd, jeśli utworzenie 17 | // pamięci się nie powiedzie zwróć błąd i wartość 1 18 | 19 | key_t key = ftok(KEY, 'a'); 20 | 21 | shmid = shmget(key, MAX, IPC_CREAT | IPC_EXCL | 0600); 22 | if (shmid == -1) { 23 | printf("problem with shmid"); 24 | return 1; 25 | } 26 | 27 | // Przyłącz segment pamięci współdzielonej do procesu do buf, obsłuż błędy i 28 | // zwróć 1 29 | 30 | buf = shmat(shmid, NULL, 0); 31 | if (buf == (void*)-1) { 32 | printf("error with shmat"); 33 | return -1; 34 | } 35 | 36 | for (i = 0; i < MAX; i++) { 37 | buf[i] = i * i; 38 | printf("Wartość: %d \n", buf[i]); 39 | } 40 | printf("Memory written\n"); 41 | // odłącz i usuń segment pamięci współdzielonej 42 | 43 | shmdt(buf); 44 | shmctl(shmid, IPC_RMID, NULL); 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_18_19/mytest_2/zad2(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -lpthread 2 | CC = gcc 3 | 4 | main: main.c 5 | $(CC) $^ -o $@ $(CFLAGS) 6 | 7 | clean: 8 | rm -f main.o main 9 | 10 | test: main 11 | @echo -e "\nTEST\n" 12 | ./main 2 5 4 13 | ./main 0 5 4 14 | 15 | all: main 16 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_18_19/mytest_2/zad3(ok)/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS = -Wall -std=c99 -lpthread 2 | CC = gcc 3 | 4 | main: main.c 5 | $(CC) $^ -o $@ $(CFLAGS) 6 | clean: 7 | rm -f main.o main 8 | 9 | test: main 10 | @echo -e "\n\nTESTING\n\n" 11 | ./main 12 | all: main test 13 | -------------------------------------------------------------------------------- /KOLOSY_SOLUSZYNS/tests_18_19/mytest_2/zad3(ok)/main.c: -------------------------------------------------------------------------------- 1 | #define _BSD_SOURCE 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define THREADS_NR 9 8 | 9 | void* hello(void* arg) { 10 | // Napisz funkcję wypisującą komunikat typu Hello (wartość_TID): 11 | // (numer_TID) 12 | // i zwracającą status o wartości równej argumentowi przesłanemu do funkcji 13 | 14 | printf("Hello!, %ld, %d \n", pthread_self(), (int*)arg); 15 | 16 | int* ind = malloc(sizeof(int)); 17 | *ind = *(int*)arg; 18 | 19 | return ind; 20 | 21 | // koniec 22 | } 23 | 24 | int main(int argc, char* argv[]) { 25 | pthread_t hello_threads[THREADS_NR]; 26 | int* count = malloc(sizeof(int)); 27 | int i; 28 | 29 | for (i = 0; i < THREADS_NR; i++) { 30 | *count = i + 1; 31 | int result = 32 | pthread_create(&hello_threads[i], NULL, hello, (void*)count); 33 | if (result != 0) { 34 | perror("Could not create thread."); 35 | } 36 | usleep(1000); 37 | } 38 | int* hello_results[THREADS_NR]; 39 | // Czekaj na zakończenie THREADS_NR wątków, pobierz status zakończenia, 40 | // zapisz go w hello_result i wypisz na ekran: Thread (indeks wątku+1) TID: 41 | // (nr_TID) returned value: (status zakonczenia watku) 42 | 43 | for (int i = 0; i < THREADS_NR; ++i) { 44 | pthread_join(hello_threads[i], (void**)&hello_results[i]); 45 | printf("Thread index: %d, TID: %ld, return value: %d \n", i + 1, 46 | hello_threads[i], *hello_results[i]); 47 | 48 | free(hello_results[i]); 49 | } 50 | 51 | // koniec 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | # MIGHTILY 11 | 12 | # VIOLENTLY 13 | 14 | # HEAVILY 15 | 16 | # ENORMOUSLY 17 | 18 | # TREMENDOUSLY 19 | 20 | # IMMENSELY 21 | 22 | # HUGELY 23 | 24 | # EXCEEDINGLY 25 | 26 | # BOUNDLESSLY 27 | 28 | # IMMEASURABLY 29 | 30 | # STAGGERINGLY 31 | 32 | # VASTLY 33 | 34 | # EXCESSIVELY 35 | 36 | # ASTRONOMICALLY 37 | 38 | # GIGANTICALLY 39 | 40 | # INSPIRED BY: 41 | 42 | - https://github.com/piotrek-szczygiel/sysopy 43 | 44 | - https://github.com/jakubdybczak/sysopy 45 | 46 | ## BUT FOR THEM, THIS REPOSITORY WOULD NOT EXIST 47 | 48 | ### IF YOU WANT WELL WRITTEN CODE, BUT MOST IMPORTANTLY WORKING CODE - GO THERE, YOU WILL NOT BE DISAPPOINTED 49 | 50 | ### "MINE" WORKS AS WELL 51 | 52 | #### In order to format code in all directories, install clang-format and then run ./format.sh in main project directory 53 | -------------------------------------------------------------------------------- /cw01/ancillary materials/Libraries - static, dynamic, shared, Make.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/cw01/ancillary materials/Libraries - static, dynamic, shared, Make.pdf -------------------------------------------------------------------------------- /cw01/zad1/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc -Wall -std=c11 -ggdb 2 | LIB_O = lib.o 3 | LIB__STATIC = lib.a 4 | LIB_SO = lib.so 5 | 6 | create: 7 | $(CC) -c -fPIC -o $(LIB_O) lib.c 8 | 9 | static: lib.c 10 | make create 11 | ar rcs $(LIB_SO) $(LIB_O) 12 | 13 | shared: 14 | make create 15 | $(CC) -o $(LIB_SO) -fPIC -shared $(LIB_O) 16 | 17 | clean: 18 | rm -f *.o 19 | rm -f *.a 20 | rm -f *.gch 21 | rm -f *.so -------------------------------------------------------------------------------- /cw01/zad1/Readme.md: -------------------------------------------------------------------------------- 1 | ## Zadanie 1. Alokacja tablicy z wskaźnikami na bloki pamięci zawierające znaki (25%) 2 | 3 | Zaprojektuj i przygotuj zestaw funkcji (bibliotekę) do zarządzania tablicą bloków, w których to blokach pamięci zapisywane są rezultaty operacji 4 | 5 | przeglądania (poleceniem find) katalogów przekazywanych jako odpowiedni parametr w poszukiwaniu plików o nazwie podanych jako kolejny parametr funkcji 6 | 7 | Biblioteka powinna umożliwiać: 8 | 9 | - utworzenie tablicy wskaźników w której będą przechowywane wskaźniki na bloki pamięci zawierające wyniki przeszukiwań, 10 | 11 | - ustawienie aktualnie przeszukiwanego katalogu oraz poszukiwanego pliku, 12 | 13 | - przeprowadzenie przeszukania tego katalogu i zapisanie wyniku poszukiwania w pliku tymczasowym 14 | 15 | - zarezerwowanie bloku pamięci o rozmiarze odpowiadającym rozmiarowi pliku tymczasowego i zapisanie w tej pamięci jego zawartości, ustawienie w tablicy wskaźników wskazania na ten blok, funkcja powinna zwrócić indeks stworzonego bloku w tablicy, 16 | 17 | - usunięcie z pamięci bloku o zadanym indeksie 18 | 19 | Tablice i bloki powinny być alokowane przy pomocy funkcji calloc (alokacja dynamiczna). 20 | 21 | Przygotuj plik Makefile, zawierający polecenia kompilujące pliki źródłowe biblioteki oraz tworzące biblioteki w dwóch wersjach: statyczną i współdzieloną. -------------------------------------------------------------------------------- /cw01/zad1/lib.c: -------------------------------------------------------------------------------- 1 | #include "lib.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | const int SIZE_OF_BUFFER = 512; 8 | 9 | int ARRAY_SIZE; 10 | 11 | struct Searcher { 12 | char* dir; 13 | char* file; 14 | char* name_file_temp; 15 | }; 16 | 17 | struct Searcher* searcher; 18 | char** result_blocks; 19 | 20 | void create_table(__uint32_t size_of_array) { 21 | searcher = calloc(size_of_array, sizeof(struct Searcher)); 22 | result_blocks = calloc(size_of_array, sizeof(char*)); 23 | ARRAY_SIZE = size_of_array; 24 | 25 | printf("Allocated array of size: %d \n", size_of_array); 26 | } 27 | 28 | void remove_block(int block_index) { 29 | free(result_blocks[block_index]); 30 | 31 | printf("Deleted block at index: %d \n", block_index); 32 | } 33 | 34 | int search_directory(char* dir, char* file, char* name_file_temp) { 35 | searcher->dir = dir; 36 | searcher->file = file; 37 | searcher->name_file_temp = name_file_temp; 38 | 39 | char buffer[SIZE_OF_BUFFER]; 40 | 41 | if (snprintf(buffer, sizeof(buffer), "find %s -name %s > %s", searcher->dir, 42 | searcher->file, searcher->name_file_temp) >= sizeof(buffer)) { 43 | printf("ERROR"); 44 | } else { 45 | system(buffer); 46 | } 47 | 48 | int fd = open(searcher->name_file_temp, O_RDONLY); 49 | long file_size = get_file_size(fd); 50 | char* result_block = calloc((size_t)file_size, sizeof(char)); 51 | read(fd, result_block, (size_t)file_size); 52 | close(fd); 53 | 54 | int block_index = -890; 55 | 56 | for (int i = 0; i < ARRAY_SIZE; ++i) { 57 | if (result_blocks[i] == NULL) { 58 | result_blocks[i] = result_block; 59 | block_index = i; 60 | break; 61 | } 62 | } 63 | 64 | return block_index; 65 | } 66 | 67 | long get_file_size(int fd) { 68 | off_t currentPos = lseek(fd, (size_t)0, SEEK_CUR); 69 | long file_size = lseek(fd, 0, SEEK_END); 70 | lseek(fd, currentPos, SEEK_SET); 71 | return file_size; 72 | } 73 | -------------------------------------------------------------------------------- /cw01/zad1/lib.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_LIBRARY_H 2 | #define SYSOPY_LIBRARY_H 3 | 4 | #include 5 | 6 | long get_file_size(int fd); 7 | void initialize_result_array(__uint32_t size_of_array); 8 | void delete_block_at_index(int block_index); 9 | int search_directory(char* dir, char* file, char* name_file_temp); 10 | 11 | #endif // SYSOPY_LIBRARY_H -------------------------------------------------------------------------------- /cw01/zad2/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc -Wall -std=c11 -ggdb 2 | 3 | SRC = main.c 4 | SRC_DYNAMIC = main_dynamic.c 5 | LIB_NAME = lib_name 6 | LIB_C = lib.c 7 | LIB_A = lib.a 8 | LIB_O = lib.o 9 | LIB_SO = lib.so 10 | LIB_DYNAMIC_O = lib_dynamic.o 11 | LIB_DYNAMIC = lib_dynamic.c 12 | OUT_STATIC = out_static 13 | OUT_SHARED = out_shared 14 | OUT_DYNAMIC = out_dynamic 15 | 16 | static: lib.c 17 | $(CC) -c $(LIB_C) 18 | ar rcs $(LIB_A) $(LIB_O) 19 | 20 | shared: lib.c 21 | $(CC) -c -fPIC $(LIB_C) 22 | gcc -shared -fPIC lib.c -o libfind.so 23 | 24 | run_static: 25 | make static 26 | $(CC) -o $(OUT_STATIC) $(SRC) $(LIB_O) 27 | make tests_static 28 | 29 | run_shared: 30 | make shared 31 | gcc -Wall -std=c99 -g main.c -L./ -lfind -o out_shared 32 | make tests_shared 33 | 34 | run_dynamic: 35 | $(CC) -o out_dynamic main.c -ldl -D DYNAMIC 36 | make tests_dynamic 37 | 38 | run_all: 39 | make run_static 40 | make run_shared 41 | make run_dynamic 42 | 43 | tests_static: 44 | # short search time 45 | LD_LIBRARY_PATH=./ ./out_static create_table 1 search_directory /usr/bin zip short.txt remove_block 0 46 | # medium search time 47 | LD_LIBRARY_PATH=./ ./out_static create_table 1 search_directory /usr lib medium.txt remove_block 0 48 | # long search time 49 | LD_LIBRARY_PATH=./ ./out_static create_table 1 search_directory / efi long.txt remove_block 0 50 | # alternately 51 | LD_LIBRARY_PATH=./ ./out_static create_table 2 search_directory /usr/bin xz tmp_4.txt remove_block 0 search_directory /usr/bin zip tmp_5.txt remove_block 1 52 | 53 | 54 | tests_shared: 55 | # short search time 56 | LD_LIBRARY_PATH=./ ./out_shared create_table 1 search_directory /usr/bin zip short.txt remove_block 0 57 | # medium search time 58 | LD_LIBRARY_PATH=./ ./out_shared create_table 1 search_directory /usr lib medium.txt remove_block 0 59 | # long search time 60 | LD_LIBRARY_PATH=./ ./out_shared create_table 1 search_directory / efi long.txt remove_block 0 61 | # alternately 62 | LD_LIBRARY_PATH=./ ./out_shared create_table 2 search_directory /usr/bin xz tmp_4.txt remove_block 0 search_directory /usr/bin zip tmp_5.txt remove_block 1 63 | 64 | 65 | tests_dynamic: 66 | # short search time 67 | LD_LIBRARY_PATH=./ ./out_dynamic create_table 1 search_directory /usr/bin zip short.txt remove_block 0 68 | # medium search time 69 | LD_LIBRARY_PATH=./ ./out_dynamic create_table 1 search_directory /usr lib medium.txt remove_block 0 70 | # long search time 71 | LD_LIBRARY_PATH=./ ./out_dynamic create_table 1 search_directory / efi long.txt remove_block 0 72 | # alternately 73 | LD_LIBRARY_PATH=./ ./out_dynamic create_table 2 search_directory /usr/bin xz tmp_4.txt remove_block 0 search_directory /usr/bin zip tmp_5.txt remove_block 1 74 | 75 | 76 | clean: 77 | rm -f *.o 78 | rm -f *.a 79 | rm -f *.gch 80 | rm -f *.so 81 | rm -f *.txt 82 | rm -f *.so.* 83 | 84 | clean_all: 85 | make clean 86 | rm -f out_static 87 | rm -f out_shared 88 | rm -f out_dynamic -------------------------------------------------------------------------------- /cw01/zad2/Readme.md: -------------------------------------------------------------------------------- 1 | ## Zadanie 2. Program korzystający z biblioteki (25%) 2 | 3 | Napisz program testujący działanie funkcji z biblioteki z zadania 1. 4 | 5 | Jako argumenty przekaż liczbę elementów tablicy oraz listę zadań do wykonania. Zadania mogą stanowić zadania przeszukania katalogów, opisane przez listę (katalog, poszukiwany plik) lub zadania usunięcia bloku o podanym indeksie. 6 | 7 | Operacje mogą być specyfikowane w linii poleceń na przykład jak poniżej: 8 | 9 | * create_table rozmiar - stworzenie tablicy o rozmiarze "rozmiar" 10 | * search_directory dir file name_file_temp wartość - wyszukanie pliku o nazwie file w katalogu dir i zapisanie wyjścia polecenia find w pliku name_file_temp 11 | * remove_block index - usuń z tablicy bloków o indeksie index 12 | 13 | 14 | Program powinien stworzyć tablice bloków o zadanej liczbie elementów 15 | 16 | W programie zmierz, wypisz na konsolę i zapisz do pliku z raportem czasy realizacji podstawowych operacji: 17 | 18 | - przeprowadzenie przeszukania katalogów o różnych poziomach zagłębień i różnych liczbach zawartych plików (omownie - dla zawierającego mało, średnią liczbę i dużo plików i podkatalogów) 19 | 20 | - zapisanie w pamięci bloków o różnych rozmiarach (odpowiadających rozmiarom różnych przeprowadzonych przeszukiwań) 21 | 22 | - usunięcie zaalokowanych bloków o różnych rozmiarach (odpowiadających rozmiarom różnych przeprowadzonych przeszukiwań) 23 | 24 | - na przemian kilkakrotne dodanie i usunięcie zadanej liczby bloków 25 | 26 | Mierząc czasy poszczególnych operacji zapisz trzy wartości: czas rzeczywisty, czas użytkownika i czas systemowy. Rezultaty umieść pliku raport2.txt i dołącz do archiwum zadania. 27 | -------------------------------------------------------------------------------- /cw01/zad2/lib.c: -------------------------------------------------------------------------------- 1 | #include "lib.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | const int SIZE_OF_BUFFER = 512; 9 | 10 | int ARRAY_SIZE; 11 | 12 | struct Searcher { 13 | char* dir; 14 | char* file; 15 | char* name_file_temp; 16 | }; 17 | 18 | struct Searcher* searcher; 19 | char** result_blocks; 20 | 21 | void create_table(__uint32_t size_of_array) { 22 | searcher = calloc(size_of_array, sizeof(struct Searcher)); 23 | result_blocks = calloc(size_of_array, sizeof(char*)); 24 | ARRAY_SIZE = size_of_array; 25 | 26 | // printf("Allocated array of size: %d \n", size_of_array); 27 | } 28 | 29 | void remove_block(int block_index) { 30 | free(result_blocks[block_index]); 31 | 32 | // printf("Deleted block at index: %d \n", block_index); 33 | } 34 | 35 | int search_directory(char* dir, char* file, char* name_file_temp) { 36 | searcher->dir = dir; 37 | searcher->file = file; 38 | searcher->name_file_temp = name_file_temp; 39 | 40 | char buffer[SIZE_OF_BUFFER]; 41 | 42 | if (snprintf(buffer, sizeof(buffer), "find %s -name %s > %s", searcher->dir, 43 | searcher->file, searcher->name_file_temp) >= sizeof(buffer)) { 44 | printf("ERROR"); 45 | } else { 46 | system(buffer); 47 | } 48 | 49 | // printf("Searching the directory: %s, for: %s, results are stored in: 50 | // %s file\n", dir, file, name_file_temp); 51 | 52 | int fd = open(searcher->name_file_temp, O_RDONLY); 53 | long file_size = get_file_size(fd); 54 | char* result_block = calloc((size_t)file_size, sizeof(char)); 55 | read(fd, result_block, (size_t)file_size); 56 | close(fd); 57 | 58 | int block_index = -1; 59 | 60 | for (int i = 0; i < ARRAY_SIZE; ++i) { 61 | if (result_blocks[i] == NULL) { 62 | result_blocks[i] = result_block; 63 | block_index = i; 64 | break; 65 | } 66 | } 67 | 68 | return block_index; 69 | } 70 | 71 | long get_file_size(int fd) { 72 | off_t currentPos = lseek(fd, (size_t)0, SEEK_CUR); 73 | long file_size = lseek(fd, 0, SEEK_END); 74 | lseek(fd, currentPos, SEEK_SET); 75 | return file_size; 76 | } 77 | -------------------------------------------------------------------------------- /cw01/zad2/lib.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_LIBRARY_H 2 | #define SYSOPY_LIBRARY_H 3 | 4 | #include 5 | 6 | long get_file_size(int fd); 7 | void create_table(__uint32_t size_of_array); 8 | void remove_block(int block_index); 9 | int search_directory(char* dir, char* file, char* name_file_temp); 10 | 11 | #endif -------------------------------------------------------------------------------- /cw01/zad2/lib_dynamic.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_LIB_DYNAMIC_H 2 | #define SYSOPY_LIB_DYNAMIC_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static void* handle = NULL; 10 | 11 | void (*_create_table)(__uint32_t size_of_array); 12 | 13 | void (*_remove_block)(int); 14 | 15 | int (*_search_directory)(char*, char*, char*); 16 | 17 | void init_dynamic_handler() { 18 | handle = dlopen("libfind.so", RTLD_LAZY); 19 | if (handle == NULL) { 20 | printf("ERROR WHILE LOADING DYNAMIC LIBRARY\n"); 21 | return; 22 | } 23 | 24 | printf("SUCCESSFUL LOADING OF DYNAMIC LIBRARY\n"); 25 | 26 | _create_table = dlsym(handle, "create_table"); 27 | 28 | if (dlerror() != NULL) { 29 | printf("COULD NOT LOAD CREATE TABLE METHOD\n"); 30 | } 31 | 32 | _remove_block = dlsym(handle, "remove_block"); 33 | if (dlerror() != NULL) { 34 | printf("COULD NOT LOAD REMOVE BLOCK METHOD\n"); 35 | } 36 | 37 | _search_directory = dlsym(handle, "search_directory"); 38 | if (dlerror() != NULL) { 39 | printf("COULD NOT LOAD SEARCH DIRECTORY METHOD\n"); 40 | } 41 | } 42 | 43 | void create_table(__uint32_t size_of_array) { 44 | (*_create_table)(size_of_array); 45 | } 46 | 47 | void remove_block(int block_index) { 48 | (*_remove_block)(block_index); 49 | } 50 | 51 | int search_directory(char* dir, char* file, char* name_file_temp) { 52 | return (*_search_directory)(dir, file, name_file_temp); 53 | } 54 | 55 | void free_handler_memory() { 56 | dlclose(handle); 57 | } 58 | 59 | #endif // SYSOPY_LIB_DYNAMIC_H 60 | -------------------------------------------------------------------------------- /cw01/zad3/Readme.md: -------------------------------------------------------------------------------- 1 | ## Zadanie 3. Testy i pomiary (50%) 2 | 3 | a) (25%) Przygotuj plik Makefile, zawierający polecenia kompilujące program z zad 2 na trzy sposoby: 4 | - z wykorzystaniem bibliotek statycznych, 5 | - z wykorzystaniem bibliotek dzielonych (dynamiczne, ładowane przy uruchomieniu programu), 6 | - z wykorzystaniem bibliotek ładowanych dynamicznie (dynamiczne, ładowane przez program), 7 | oraz uruchamiający testy. 8 | 9 | Wyniki pomiarów zbierz w pliku results3a.txt. Otrzymane wyniki krótko skomentuj. 10 | 11 | b) (25%) Rozszerz plik Makefile z punktu 3a) dodając możliwość skompilowania programu na trzech różnych poziomach optymalizacji -O0...-Os. Przeprowadź ponownie pomiary kompilując i uruchamiając program dla rożnych poziomów optymalizacji. 12 | 13 | Wyniki pomiarów dodaj do pliku results3b.txt. Otrzymane wyniki krotko skomentuj. 14 | 15 | Wygenerowane pliki z raportami załącz jako element rozwiązania. 16 | 17 | Uwaga: Do odczytania pliku można użyć funkcji read (man read), do wywołania zewnętrznego polecenia Unixa można użyć funkcji system (man system). 18 | -------------------------------------------------------------------------------- /cw01/zad3/zad3a/lib.c: -------------------------------------------------------------------------------- 1 | #include "lib.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | const int SIZE_OF_BUFFER = 512; 9 | 10 | int ARRAY_SIZE; 11 | 12 | struct Searcher { 13 | char* dir; 14 | char* file; 15 | char* name_file_temp; 16 | }; 17 | 18 | struct Searcher* searcher; 19 | char** result_blocks; 20 | 21 | void create_table(__uint32_t size_of_array) { 22 | searcher = calloc(size_of_array, sizeof(struct Searcher)); 23 | result_blocks = calloc(size_of_array, sizeof(char*)); 24 | ARRAY_SIZE = size_of_array; 25 | 26 | // printf("Allocated array of size: %d \n", size_of_array); 27 | } 28 | 29 | void remove_block(int block_index) { 30 | free(result_blocks[block_index]); 31 | 32 | // printf("Deleted block at index: %d \n", block_index); 33 | } 34 | 35 | int search_directory(char* dir, char* file, char* name_file_temp) { 36 | searcher->dir = dir; 37 | searcher->file = file; 38 | searcher->name_file_temp = name_file_temp; 39 | 40 | char buffer[SIZE_OF_BUFFER]; 41 | 42 | if (snprintf(buffer, sizeof(buffer), "find %s -name %s > %s", searcher->dir, 43 | searcher->file, searcher->name_file_temp) >= sizeof(buffer)) { 44 | printf("ERROR"); 45 | } else { 46 | system(buffer); 47 | } 48 | 49 | // printf("Searching the directory: %s, for: %s, results are stored in: 50 | // %s file\n", dir, file, name_file_temp); 51 | 52 | int fd = open(searcher->name_file_temp, O_RDONLY); 53 | long file_size = get_file_size(fd); 54 | char* result_block = calloc((size_t)file_size, sizeof(char)); 55 | read(fd, result_block, (size_t)file_size); 56 | close(fd); 57 | 58 | int block_index = -1; 59 | 60 | for (int i = 0; i < ARRAY_SIZE; ++i) { 61 | if (result_blocks[i] == NULL) { 62 | result_blocks[i] = result_block; 63 | block_index = i; 64 | break; 65 | } 66 | } 67 | 68 | return block_index; 69 | } 70 | 71 | long get_file_size(int fd) { 72 | off_t currentPos = lseek(fd, (size_t)0, SEEK_CUR); 73 | long file_size = lseek(fd, 0, SEEK_END); 74 | lseek(fd, currentPos, SEEK_SET); 75 | return file_size; 76 | } 77 | -------------------------------------------------------------------------------- /cw01/zad3/zad3a/lib.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_LIBRARY_H 2 | #define SYSOPY_LIBRARY_H 3 | 4 | #include 5 | 6 | long get_file_size(int fd); 7 | void create_table(__uint32_t size_of_array); 8 | void remove_block(int block_index); 9 | int search_directory(char* dir, char* file, char* name_file_temp); 10 | 11 | #endif -------------------------------------------------------------------------------- /cw01/zad3/zad3a/lib_dynamic.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_LIB_DYNAMIC_H 2 | #define SYSOPY_LIB_DYNAMIC_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static void* handle = NULL; 10 | 11 | void (*_create_table)(__uint32_t size_of_array); 12 | 13 | void (*_remove_block)(int); 14 | 15 | int (*_search_directory)(char*, char*, char*); 16 | 17 | void init_dynamic_handler() { 18 | handle = dlopen("libfind.so", RTLD_LAZY); 19 | if (handle == NULL) { 20 | printf("ERROR WHILE LOADING DYNAMIC LIBRARY\n"); 21 | return; 22 | } 23 | 24 | printf("SUCCESSFUL LOADING OF DYNAMIC LIBRARY\n"); 25 | 26 | _create_table = dlsym(handle, "create_table"); 27 | 28 | if (dlerror() != NULL) { 29 | printf("COULD NOT LOAD CREATE TABLE METHOD\n"); 30 | } 31 | 32 | _remove_block = dlsym(handle, "remove_block"); 33 | if (dlerror() != NULL) { 34 | printf("COULD NOT LOAD REMOVE BLOCK METHOD\n"); 35 | } 36 | 37 | _search_directory = dlsym(handle, "search_directory"); 38 | if (dlerror() != NULL) { 39 | printf("COULD NOT LOAD SEARCH DIRECTORY METHOD\n"); 40 | } 41 | } 42 | 43 | void create_table(__uint32_t size_of_array) { 44 | (*_create_table)(size_of_array); 45 | } 46 | 47 | void remove_block(int block_index) { 48 | (*_remove_block)(block_index); 49 | } 50 | 51 | int search_directory(char* dir, char* file, char* name_file_temp) { 52 | return (*_search_directory)(dir, file, name_file_temp); 53 | } 54 | 55 | void free_handler_memory() { 56 | dlclose(handle); 57 | } 58 | 59 | #endif // SYSOPY_LIB_DYNAMIC_H 60 | -------------------------------------------------------------------------------- /cw01/zad3/zad3b/lib.c: -------------------------------------------------------------------------------- 1 | #include "lib.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | const int SIZE_OF_BUFFER = 512; 9 | 10 | int ARRAY_SIZE; 11 | 12 | struct Searcher { 13 | char* dir; 14 | char* file; 15 | char* name_file_temp; 16 | }; 17 | 18 | struct Searcher* searcher; 19 | char** result_blocks; 20 | 21 | void create_table(__uint32_t size_of_array) { 22 | searcher = calloc(size_of_array, sizeof(struct Searcher)); 23 | result_blocks = calloc(size_of_array, sizeof(char*)); 24 | ARRAY_SIZE = size_of_array; 25 | 26 | // printf("Allocated array of size: %d \n", size_of_array); 27 | } 28 | 29 | void remove_block(int block_index) { 30 | free(result_blocks[block_index]); 31 | 32 | // printf("Deleted block at index: %d \n", block_index); 33 | } 34 | 35 | int search_directory(char* dir, char* file, char* name_file_temp) { 36 | searcher->dir = dir; 37 | searcher->file = file; 38 | searcher->name_file_temp = name_file_temp; 39 | 40 | char buffer[SIZE_OF_BUFFER]; 41 | 42 | if (snprintf(buffer, sizeof(buffer), "find %s -name %s > %s", searcher->dir, 43 | searcher->file, searcher->name_file_temp) >= sizeof(buffer)) { 44 | printf("ERROR"); 45 | } else { 46 | system(buffer); 47 | } 48 | 49 | // printf("Searching the directory: %s, for: %s, results are stored in: 50 | // %s file\n", dir, file, name_file_temp); 51 | 52 | int fd = open(searcher->name_file_temp, O_RDONLY); 53 | long file_size = get_file_size(fd); 54 | char* result_block = calloc((size_t)file_size, sizeof(char)); 55 | read(fd, result_block, (size_t)file_size); 56 | close(fd); 57 | 58 | int block_index = -1; 59 | 60 | for (int i = 0; i < ARRAY_SIZE; ++i) { 61 | if (result_blocks[i] == NULL) { 62 | result_blocks[i] = result_block; 63 | block_index = i; 64 | break; 65 | } 66 | } 67 | 68 | return block_index; 69 | } 70 | 71 | long get_file_size(int fd) { 72 | off_t currentPos = lseek(fd, (size_t)0, SEEK_CUR); 73 | long file_size = lseek(fd, 0, SEEK_END); 74 | lseek(fd, currentPos, SEEK_SET); 75 | return file_size; 76 | } 77 | -------------------------------------------------------------------------------- /cw01/zad3/zad3b/lib.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_LIBRARY_H 2 | #define SYSOPY_LIBRARY_H 3 | 4 | #include 5 | 6 | long get_file_size(int fd); 7 | void create_table(__uint32_t size_of_array); 8 | void remove_block(int block_index); 9 | int search_directory(char* dir, char* file, char* name_file_temp); 10 | 11 | #endif -------------------------------------------------------------------------------- /cw01/zad3/zad3b/lib_dynamic.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_LIB_DYNAMIC_H 2 | #define SYSOPY_LIB_DYNAMIC_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static void* handle = NULL; 10 | 11 | void (*_create_table)(__uint32_t size_of_array); 12 | 13 | void (*_remove_block)(int); 14 | 15 | int (*_search_directory)(char*, char*, char*); 16 | 17 | void init_dynamic_handler() { 18 | handle = dlopen("libfind.so", RTLD_LAZY); 19 | if (handle == NULL) { 20 | printf("ERROR WHILE LOADING DYNAMIC LIBRARY\n"); 21 | return; 22 | } 23 | 24 | printf("SUCCESSFUL LOADING OF DYNAMIC LIBRARY\n"); 25 | 26 | _create_table = dlsym(handle, "create_table"); 27 | 28 | if (dlerror() != NULL) { 29 | printf("COULD NOT LOAD CREATE TABLE METHOD\n"); 30 | } 31 | 32 | _remove_block = dlsym(handle, "remove_block"); 33 | if (dlerror() != NULL) { 34 | printf("COULD NOT LOAD REMOVE BLOCK METHOD\n"); 35 | } 36 | 37 | _search_directory = dlsym(handle, "search_directory"); 38 | if (dlerror() != NULL) { 39 | printf("COULD NOT LOAD SEARCH DIRECTORY METHOD\n"); 40 | } 41 | } 42 | 43 | void create_table(__uint32_t size_of_array) { 44 | (*_create_table)(size_of_array); 45 | } 46 | 47 | void remove_block(int block_index) { 48 | (*_remove_block)(block_index); 49 | } 50 | 51 | int search_directory(char* dir, char* file, char* name_file_temp) { 52 | return (*_search_directory)(dir, file, name_file_temp); 53 | } 54 | 55 | void free_handler_memory() { 56 | dlclose(handle); 57 | } 58 | 59 | #endif // SYSOPY_LIB_DYNAMIC_H 60 | -------------------------------------------------------------------------------- /cw02/ancillary materials/FileSystem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/cw02/ancillary materials/FileSystem.pdf -------------------------------------------------------------------------------- /cw02/zad1/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc -Wall -ggdb 2 | 3 | create_outfile: 4 | $(CC) -o out_main main.c 5 | 6 | generate_tests: 7 | ./out_main generate test.txt 10000 1 8 | ./out_main generate test2.txt 8000 4 9 | ./out_main generate test3.txt 6000 512 10 | ./out_main generate test4.txt 4000 4096 11 | ./out_main generate test5.txt 2000 8192 12 | 13 | sort_lib_test: 14 | ./out_main sort test.txt 10000 1 lib 15 | ./out_main sort test2.txt 8000 4 lib 16 | ./out_main sort test3.txt 6000 512 lib 17 | ./out_main sort test4.txt 4000 4096 lib 18 | ./out_main sort test5.txt 2000 8192 lib 19 | 20 | sort_sys_test: 21 | ./out_main sort test.txt 10000 1 sys 22 | ./out_main sort test2.txt 8000 4 sys 23 | ./out_main sort test3.txt 6000 512 sys 24 | ./out_main sort test4.txt 4000 4096 sys 25 | ./out_main sort test5.txt 2000 8192 sys 26 | 27 | copy_lib_test: 28 | ./out_main copy test.txt test_.txt 10000 1 lib 29 | ./out_main copy test.txt test_2.txt 8000 4 lib 30 | ./out_main copy test.txt test_3.txt 6000 512 lib 31 | ./out_main copy test.txt test_4.txt 4000 4096 lib 32 | ./out_main copy test.txt test_5.txt 2000 8192 lib 33 | 34 | copy_sys_test: 35 | ./out_main copy test.txt test_.txt 10000 1 sys 36 | ./out_main copy test.txt test_2.txt 8000 4 sys 37 | ./out_main copy test.txt test_3.txt 6000 512 sys 38 | ./out_main copy test.txt test_4.txt 4000 4096 sys 39 | ./out_main copy test.txt test_5.txt 2000 8192 sys 40 | 41 | run_sort_lib: 42 | make create_outfile 43 | make generate_tests 44 | make sort_lib_test 45 | 46 | run_sort_sys: 47 | make create_outfile 48 | make generate_tests 49 | make sort_sys_test 50 | 51 | run_copy_lib: 52 | make create_outfile 53 | make generate_tests 54 | make copy_lib_test 55 | 56 | run_copy_sys: 57 | make create_outfile 58 | make generate_tests 59 | make copy_sys_test 60 | 61 | 62 | clean: 63 | rm -f out_main 64 | rm -f *.txt 65 | -------------------------------------------------------------------------------- /cw02/zad1/Readme.md: -------------------------------------------------------------------------------- 1 | ## Zadanie 1 - Porównanie wydajności systemowych i bibliotecznych funkcji we/wy 2 | Celem zadania jest napisanie programu porównującego wydajność systemowych i bibliotecznych funkcji wejścia/wyjścia. 3 | Program operował będzie na przechowywanej w pliku tablicy rekordów. Dla uproszczenia pojedynczy rekord będzie tablicą bajtów o stałej wielkości. 4 | Nazwa pliku, wielkość oraz liczba rekordów stanowić będą argumenty wywołania programu. 5 | 6 | Program udostępniać powinien operacje: 7 | * generate - tworzenie pliku z rekordami wypełnionego wygenerowaną losową zawartością (można wykorzystać wirtualny generator /dev/random lub w wersji uproszczonej funkcję rand) 8 | * sort - sortuje rekordy w pliku używając sortowania przez proste wybieranie. Kluczem do sortowania niech będzie wartość pierwszego bajtu rekordu (interpretowanego jako liczba bez znaku - unsigned char) Podczas sortowania w pamięci powinny być przechowywane jednocześnie najwyżej dwa rekordy (sprowadza się do zamieniania miejscami i porównywania dwóch rekordów). 9 | * copy - kopiuje plik1 do pliku2. Kopiowanie powinno odbywać się za pomocą bufora o zadanej wielkości rekordu. 10 | 11 | Sortowanie i kopiowanie powinno być zaimplementowane w dwóch wariantach: 12 | * sys - przy użyciu funkcji systemowych: read i write 13 | * lib - przy użyciu funkcji biblioteki C: fread i fwrite 14 | 15 | Rodzaj operacji oraz sposób dostępu do plików ma być wybierany na podstawie argumentu wywołania - np.: 16 | * ./program generate dane 100 512 powinno losowo generować 100 rekordów o długości 512 bajtów 17 | do pliku dane, 18 | * ./program sort dane 100 512 sys powinien sortować rekordy w pliku dane przy użyciu funkcji systemowych, 19 | zakładając że zawiera on 100 rekordów wielkości 512 bajtów 20 | * ./program copy plik1 plik2 100 512 lib powinno skopiować 100 rekordów pliku 1 do pliku 2 za pomocą funkcji 21 | bibliotecznych z wykorzystaniem bufora 512 bajtów 22 | 23 | Dla obu wariantów implementacji przeprowadź pomiary czasu użytkownika i czasu systemowego operacji sortowania i kopiowania. 24 | Testy wykonaj dla następujących rozmiarów rekordu: 1, 4, 512, 1024, 4096 i 8192 bajty. 25 | Dla każdego rozmiaru rekordu wykonaj dwa testy różniące się liczbą rekordów w sortowanym pliku. 26 | Liczby rekordów dobierz tak, by czas sortowania mieścił się w przedziale od kilku do kilkudziesięciu sekund. 27 | Porównując dwa warianty implementacji należy korzystać z identycznego pliku do sortowania (po wygenerowaniu, a przed sortowaniem, utwórz jego kopię). 28 | Zmierzone czasy zestaw w pliku wyniki.txt. Do pliku dodaj komentarz podsumowujący wnioski z testów. 29 | -------------------------------------------------------------------------------- /cw02/zad2/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc -Wall -ggdb 2 | 3 | create_outfile: 4 | $(CC) -o out_main main.c 5 | 6 | generate_test: 7 | ./out_main "/home/jakub/IdeaProjects" "<" "2019.03.13 15:18" 8 | 9 | run: 10 | make create_outfile 11 | make generate_test 12 | 13 | clean: 14 | rm -f out_main -------------------------------------------------------------------------------- /cw02/zad2/Readme.md: -------------------------------------------------------------------------------- 1 | ## Zadanie 2. Operacje na strukturze katalogów (45%) 2 | Napisz program wyszukujący w drzewie katalogu (ścieżka do katalogu jest pierwszym argumentem programu), 3 | w zależności od wartości drugiego argumentu ('<', '>','=') , pliki zwykłe z datą modyfikacji wcześniejszą, późniejszą lub 4 | równą dacie podanej jako trzeci argument programu. Program ma wypisać na standardowe wyjście następujące informacje znalezionych plików: 5 | 6 | * ścieżka bezwzględna pliku, 7 | * rodzaj pliku (zwykły plik - file, katalog - dir, urządzenie znakowe - char dev, urządzenie blokowe - block dev, potok nazwany - fifo, link symboliczny - slink, soket - sock) 8 | * rozmiar w bajtach, 9 | * datę ostatniego dostępu, 10 | * datę ostatniej modyfikacji. 11 | 12 | Ścieżka podana jako argument wywołania może być względna lub bezwzględna. Program nie powinien podążać za dowiązaniami symbolicznymi do katalogów. 13 | 14 | Program należy zaimplementować w dwóch wariantach: 15 | * Korzystając z funkcji opendir, readdir oraz funkcji z rodziny stat (25%) 16 | * Korzystając z funkcji nftw (20%) 17 | * W ramach testowania funkcji utwórz w badanej strukturze katalogów jakieś dowiązania symboliczne, zwykłe pliki i katalogi. 18 | -------------------------------------------------------------------------------- /cw03/ancillary materials/Processes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/cw03/ancillary materials/Processes.pdf -------------------------------------------------------------------------------- /cw03/ancillary materials/Processes_v2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/cw03/ancillary materials/Processes_v2.pdf -------------------------------------------------------------------------------- /cw03/zad1/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc -Wall -ggdb 2 | 3 | create_outfile: 4 | $(CC) -o out_main main.c 5 | 6 | generate_test: 7 | ./out_main ~/CLionProjects/sysopy/ 8 | 9 | run: 10 | make create_outfile 11 | make generate_test 12 | 13 | clean: 14 | rm -f out_main -------------------------------------------------------------------------------- /cw03/zad1/Readme.md: -------------------------------------------------------------------------------- 1 | ## Zadanie 1. Drzewo procesów (15%) 2 | Modyfikując zadanie 2 z poprzedniego zestawu, napisz program, który dla każdego z podkatalogów utworzy proces potomny i wywoła polecenie ls -l. Wynik ls poprzedź wypisaniem ścieżki względnej od katalogu podanego jako argument oraz numeru PID procesu odpowiedzialnego za przeglądanie określonego poziomu. 3 | -------------------------------------------------------------------------------- /cw03/zad1/main.c: -------------------------------------------------------------------------------- 1 | #define _XOPEN_SOURCE 500 2 | #define __USE_XOPEN 1 3 | #define _GNU_SOURCE 1 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | void search_directory() { 18 | DIR* directory = opendir("."); 19 | if (directory == NULL) { 20 | printf("PROBLEM WITH OPENING DIRECTORY!\n"); 21 | return; 22 | } 23 | 24 | struct dirent* reader; 25 | 26 | while ((reader = readdir(directory)) != NULL) { 27 | struct stat status; 28 | 29 | lstat(reader->d_name, &status); 30 | 31 | if (S_ISDIR(status.st_mode)) { 32 | if (strcmp(reader->d_name, ".") == 0 || 33 | strcmp(reader->d_name, "..") == 0) { 34 | continue; 35 | } 36 | 37 | if (chdir(reader->d_name) != 0) { 38 | printf("ERROR WHILE OPENING %s\n", reader->d_name); 39 | } 40 | 41 | search_directory(); 42 | 43 | pid_t child_pid; 44 | child_pid = fork(); 45 | 46 | if (child_pid == -1) { 47 | printf("FORK PROBLEM!\n"); 48 | } else if (child_pid > 0) { 49 | int st; 50 | waitpid(child_pid, &st, 0); 51 | } else { 52 | char cwd_buff[2048]; 53 | if (getcwd(cwd_buff, 2048) == NULL) { 54 | printf( 55 | "PROBLEM WITH CHANGING PATH TO CURRENT DIRECTORY!\n"); 56 | } 57 | 58 | printf("%s\n", cwd_buff); 59 | execl("/bin/ls", "ls", "-l", NULL); 60 | } 61 | 62 | if (chdir("..") != 0) { 63 | printf("PROBLEM WITH CHANGING PATH TO %s /../\n", 64 | reader->d_name); 65 | } 66 | } 67 | } 68 | closedir(directory); 69 | } 70 | 71 | int main(int argc, char** argv) { 72 | if (argc != 2) { 73 | printf("WRONG NUMBER OF ARGUMENTS\n!"); 74 | return -1; 75 | } 76 | 77 | char* path = argv[1]; 78 | 79 | printf("RECURSIVE: \n\n"); 80 | 81 | if (chdir(path) != 0) { 82 | printf("PROBLEM WITH CHANGING THE PATH TO: %s\n", path); 83 | return -1; 84 | } 85 | 86 | search_directory(); 87 | } 88 | -------------------------------------------------------------------------------- /cw03/zad2/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc -Wall -ggdb 2 | 3 | create_outfile: 4 | $(CC) -o out_main main.c 5 | 6 | generate_test: 7 | ./out_main /home/jakub/CLionProjects/sysopy/cw03/zad2/list.txt 10 standard 8 | 9 | run: 10 | make create_outfile 11 | make generate_test 12 | 13 | clean: 14 | rm -f out_main -------------------------------------------------------------------------------- /cw03/zad2/Readme.md: -------------------------------------------------------------------------------- 1 | ## Zadanie 2. Kopie zapasowe plików (50%) 2 | Napisz program monitor do robienia kopii zapasowych plików, zawartych w pliku lista podawanym jako argument programu. Plik lista zawiera w pojedynczej linii nazwę monitorowanego pliku wraz ze ścieżką względną bądź bezwzględną oraz liczbę, co ile sekund plik ma być monitorowany. Dla każdego pliku z lista program monitor tworzy odpowiednią liczbę procesów potomnych, aby każdy monitorował jeden plik. Drugim argumentem programu monitor jest czas monitorowania wyrażony w sekundach. Po upłynięciu tego czasu każdy z procesów potomnych kończy swoje działanie, zwracając do procesu macierzystego poprzez kod wyjścia procesu liczbę wykonanych kopii pliku. Program macierzysty pobiera statusy procesów potomnych, wypisuje raport: "Proces PID utworzył n kopii pliku" i kończy swoje działanie. UWAGA! Nie używamy sygnałów, które są tematem następnych zajęć. 3 | 4 | Kopiowanie pliku może odbywać się na dwa sposoby: (tryb - trzeci argument programu) 5 | 6 | Proces kopiuje do pamięci zawartość monitorowanego pliku oraz datę jego ostatniej modyfikacji, po czym jeśli data modyfikacji pliku (a tym samym zawartość pliku) zostanie zmieniona, to proces zapisuje skopiowaną do pamięci starą wersję pliku we wspólnym dla wszystkich podkatalogu archiwum a do pamięci zapisuje aktualną wersję pliku. 7 | Plik nie jest zapisywany w pamięci, natomiast na samym początku oraz po każdej zanotowanej modyfikacji pliku, proces utworzy nowy proces, który wywoła jedną z funkcji z rodziny exec, aby wykonać cp. 8 | Nazwa pliku utworzonej kopii to nazwa monitorowanego pliku, rozszerzona o datę modyfikacji pliku w formacie: _RRRR-MM-DD_GG-MM-SS. 9 | 10 | Napisz pomocniczy testowy program tester, przyjmujący argumenty: plik, pmin pmax i bytes, który do zadanego jako pierwszy argument pliku z losową częstością od pmin do pmax wyrażoną w sekundach dopisuje na jego koniec linię tekstu zawierającą pid procesu, wylosowaną liczbę sekund, aktualną datę i czas (nie liczą się do liczby bajtów) oraz dowolnego ciągu znaków o długości określonej w bytes. Program ten pozwoli w krótkim czasie wygenerować kilka wersji kopii zapasowych. 11 | -------------------------------------------------------------------------------- /cw03/zad2/list.txt: -------------------------------------------------------------------------------- 1 | /home/jakub/CLionProjects/sysopy/cw03/zad2/test/test1 2 2 | /home/jakub/CLionProjects/sysopy/cw03/zad2/test/test 2 3 | /home/jakub/CLionProjects/sysopy/cw03/zad2/test/test2 2 4 | -------------------------------------------------------------------------------- /cw03/zad2/test/test: -------------------------------------------------------------------------------- 1 | dssdjjdsios 2 | dsasd -------------------------------------------------------------------------------- /cw03/zad2/test/test1: -------------------------------------------------------------------------------- 1 | sdkoakdasokdsdsadsadasdsdsadas -------------------------------------------------------------------------------- /cw03/zad2/test/test2: -------------------------------------------------------------------------------- 1 | dsauhdushasds -------------------------------------------------------------------------------- /cw03/zad3/Makefile: -------------------------------------------------------------------------------- 1 | CC := gcc 2 | CFLAGS := -Wall -O3 -std=c99 3 | HEADERS := error.h 4 | SRC := monitor.c backup.c error.c 5 | NAME := monitor 6 | 7 | $(NAME): $(HEADERS) $(SRC) 8 | $(CC) $(CFLAGS) $(SRC) -o $(NAME) 9 | 10 | tester: tester.c 11 | $(CC) $(CFLAGS) tester.c -o tester 12 | 13 | clean: 14 | $(RM) -rf $(NAME) tester files archive 15 | 16 | test: clean $(NAME) tester 17 | mkdir "files" 18 | echo "files/file_1 1" > files/list1 19 | echo "files/file_2 2" >> files/list1 20 | echo "files/file_3 3" > files/list2 21 | echo "files/file_4 2" >> files/list2 22 | 23 | ./tester files/file_1 1 3 16 & 24 | ./tester files/file_2 1 3 16 & 25 | ./tester files/file_3 1 3 16 & 26 | ./tester files/file_4 1 3 16 & 27 | 28 | ./monitor files/list1 10 exec 1 7 & 29 | sleep 1 30 | ./monitor files/list2 10 mem 1 3 & 31 | sleep 11 32 | pkill tester 33 | -------------------------------------------------------------------------------- /cw03/zad3/Readme.md: -------------------------------------------------------------------------------- 1 | ## Zadanie 3. Zasoby procesów (35%) 2 | Zmodyfikuj program z Zadania 2 tak, aby każdy kopiujący proces miał nałożone pewne twarde ograniczenie na dostępny czas procesora oraz rozmiar pamięci wirtualnej. Wartości tych ograniczeń (odpowiednio w sekundach i megabajtach) powinny być przekazywane jako czwarty i piąty argument wywołania monitora. Ograniczenia powinny być nakładane przez proces potomny, w tym celu należy użyć funkcji setrlimit. Zakładamy, że wartości nakładanych ograniczeń są dużo niższe (t.j. bardziej restrykcyjne) niż ograniczenia, które system operacyjny narzuca na użytkownika uruchamiającego monitor. 3 | 4 | Zaimplementuj w monitorze raportowanie zużycia zasobów systemowych dla każdego procesu potomnego, w tym czas użytkownika i czas systemowy. Realizując tę część zadania zwróć uwagę na funkcję getrusage i flagę RUSAGE_CHILDREN. 5 | -------------------------------------------------------------------------------- /cw03/zad3/backup.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "error.h" 10 | 11 | static char* backup_mem_buffer; 12 | static long backup_mem_buffer_size; 13 | 14 | char* get_backup_name(const char* filename) { 15 | time_t rawtime; 16 | struct tm* timeinfo; 17 | char* buffer = malloc(4096); 18 | 19 | time(&rawtime); 20 | timeinfo = localtime(&rawtime); 21 | 22 | char date[80]; 23 | strftime(date, sizeof(date), "%Y-%m-%d_%H-%M-%S", timeinfo); 24 | 25 | char* filename_copy = malloc(4096); 26 | strcpy(filename_copy, filename); 27 | sprintf(buffer, "archive/%s_%s", basename(filename_copy), date); 28 | return buffer; 29 | } 30 | 31 | void backup_exec(const char* filename) { 32 | char* backup_name = get_backup_name(filename); 33 | 34 | pid_t child_pid = fork(); 35 | 36 | if (child_pid == -1) { 37 | perr("unable to fork"); 38 | } else if (child_pid > 0) { 39 | int status; 40 | waitpid(child_pid, &status, 0); 41 | } else { 42 | execlp("cp", "cp", filename, backup_name, NULL); 43 | _exit(EXIT_FAILURE); 44 | } 45 | 46 | printf("PID: %d (EXEC)\t%s -> %s\n", getpid(), filename, backup_name); 47 | 48 | free(backup_name); 49 | } 50 | 51 | void backup_mem_read(const char* filename) { 52 | FILE* file = fopen(filename, "rb"); 53 | if (file == NULL) { 54 | perr("unable to open %s", filename); 55 | } 56 | 57 | fseek(file, 0, SEEK_END); 58 | backup_mem_buffer_size = ftell(file); 59 | backup_mem_buffer = realloc(backup_mem_buffer, backup_mem_buffer_size); 60 | rewind(file); 61 | fread(backup_mem_buffer, backup_mem_buffer_size, 1, file); 62 | fclose(file); 63 | } 64 | 65 | void backup_mem(const char* filename) { 66 | char* backup_name = get_backup_name(filename); 67 | 68 | FILE* file = fopen(backup_name, "wb"); 69 | if (file == NULL) { 70 | perr("unable to open %s", backup_name); 71 | } 72 | 73 | fwrite(backup_mem_buffer, backup_mem_buffer_size, 1, file); 74 | fclose(file); 75 | 76 | printf("PID: %d (MEM) \t%s -> %s\n", getpid(), filename, backup_name); 77 | 78 | free(backup_name); 79 | backup_mem_read(filename); 80 | } 81 | -------------------------------------------------------------------------------- /cw03/zad3/backup.h: -------------------------------------------------------------------------------- 1 | #ifndef BACKUP_H 2 | #define BACKUP_H 3 | 4 | void backup_exec(const char* filename); 5 | void backup_mem(const char* filename); 6 | void backup_mem_read(const char* filename); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /cw03/zad3/error.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | void err(const char* format, ...) { 8 | va_list args; 9 | va_start(args, format); 10 | vfprintf(stderr, format, args); 11 | va_end(args); 12 | fputs("\n", stderr); 13 | exit(1); 14 | } 15 | 16 | void perr(const char* format, ...) { 17 | va_list args; 18 | va_start(args, format); 19 | vfprintf(stderr, format, args); 20 | fprintf(stderr, ": %s\n", strerror(errno)); 21 | exit(1); 22 | } 23 | -------------------------------------------------------------------------------- /cw03/zad3/error.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_ERROR_H 2 | #define LIST_ERROR_H 3 | 4 | void err(const char* format, ...); 5 | void perr(const char* format, ...); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /cw03/zad3/tester.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "error.h" 7 | 8 | int main(int argc, char* argv[]) { 9 | if (argc != 5) { 10 | err("usage: %s [file] [interval_min] [interval_max] [bytes]", argv[0]); 11 | } 12 | 13 | char* filename = argv[1]; 14 | 15 | char* end; 16 | int interval_min = strtol(argv[2], &end, 10); 17 | if (end == argv[2]) { 18 | err("cannot convert '%s' to a number", argv[2]); 19 | } 20 | 21 | int interval_max = strtol(argv[3], &end, 10); 22 | if (end == argv[3]) { 23 | err("cannot convert '%s' to a number", argv[3]); 24 | } 25 | 26 | int bytes = strtol(argv[4], &end, 10); 27 | if (end == argv[4]) { 28 | err("cannot convert '%s' to a number", argv[4]); 29 | } 30 | 31 | if (interval_min > interval_max) { 32 | err("interval_min should be lower than interval_max"); 33 | } 34 | 35 | srand(time(NULL)); 36 | 37 | FILE* f; 38 | char* random_buffer = malloc(bytes); 39 | time_t rawtime; 40 | struct tm* timeinfo; 41 | char date[80]; 42 | 43 | while (1) { 44 | int sleep_interval = 45 | interval_min + (rand() % (interval_max - interval_min + 1)); 46 | 47 | time(&rawtime); 48 | timeinfo = localtime(&rawtime); 49 | strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", timeinfo); 50 | 51 | f = fopen("/dev/urandom", "rb"); 52 | fread(random_buffer, bytes, 1, f); 53 | fclose(f); 54 | 55 | f = fopen(filename, "a"); 56 | fprintf(f, "pid: %d sleep: %d date: %s\nbytes: ", getpid(), 57 | sleep_interval, date); 58 | fwrite(random_buffer, bytes, 1, f); 59 | fputs("\n\n", f); 60 | fclose(f); 61 | 62 | sleep(sleep_interval); 63 | } 64 | 65 | free(random_buffer); 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /cw04/ancillary materials/Signals.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/cw04/ancillary materials/Signals.pdf -------------------------------------------------------------------------------- /cw04/zad1a/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc -Wall -ggdb 2 | 3 | out_file: main.c 4 | $(CC) -o out_file main.c 5 | 6 | test: out_file 7 | ./out_file 8 | 9 | clean: out_file 10 | rm out_file -------------------------------------------------------------------------------- /cw04/zad1a/Readme.md: -------------------------------------------------------------------------------- 1 | ## Zadanie 1 (25%) 2 | Napisz program wypisujący w pętli nieskończonej aktualną datę i godzinę. Po odebraniu sygnału SIGTSTP (CTRL+Z) program zatrzymuje się, wypisując komunikat "Oczekuję na CTRL+Z - kontynuacja albo CTR+C - zakończenie programu". Po ponownym wysłaniu SIGTSTP program powraca do pierwotnego wypisywania. 3 | 4 | Program powinien również obsługiwać sygnał SIGINT. Po jego odebraniu program wypisuje komunikat "Odebrano sygnał SIGINT" i kończy działanie. W kodzie programu, do przechwycenia sygnałów użyj zarówno funkcji signal, jak i sigaction (np. SIGINT odbierz za pomocą signal, a SIGTSTP za pomocą sigaction). 5 | 6 | Zrealizuj powyższe zadanie, tworząc program potomny, który będzie wywoływał jedną z funkcji z rodziny exec skrypt shellowy zawierający zapętlone systemowe polecenie date. Proces macierzysty będzie przychwytywał powyższe sygnały i przekazywał je do procesu potomnego, tj po otrzymaniu SIGTSTP kończy proces potomka, a jeśli ten został wcześniej zakończony, tworzy nowy, wznawiając działanie skryptu, a po otrzymaniu SIGINT kończy działanie potomka (jeśli ten jeszcze pracuje) oraz programu. 7 | 8 | -------------------------------------------------------------------------------- /cw04/zad1a/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | static int is_running = 1; 9 | 10 | void ctrl_c_handle_SIGINT(int sg) { 11 | printf("\nCtrl C pressed - end of program\n"); 12 | exit(sg); 13 | } 14 | 15 | void ctrl_z_handle_SIGTSTP(int sg) { 16 | printf( 17 | "\nCtrl Z pressed - continue with Ctrl Z or terminate with Ctrl C\n"); 18 | 19 | is_running = 1 - is_running; 20 | } 21 | 22 | int main(int argc, char** argv) { 23 | signal(SIGINT, ctrl_c_handle_SIGINT); 24 | 25 | struct sigaction sigaction1; 26 | // memset(&sigaction1, 0, sizeof(struct sigaction)); 27 | sigaction1.sa_handler = ctrl_z_handle_SIGTSTP; 28 | sigaction1.sa_flags = 0; 29 | sigaction(SIGTSTP, &sigaction1, NULL); 30 | 31 | time_t actual_time; 32 | struct tm* time_info; 33 | 34 | printf("\nPRESS CTRL Z TO PAUSE (CONTINUE) OR CTRL C TO TERMINATE\n"); 35 | 36 | while (1) { 37 | if (is_running) { 38 | time(&actual_time); 39 | time_info = localtime(&actual_time); 40 | 41 | printf("Actual time: %s", asctime(time_info)); 42 | sleep(1); 43 | } else { 44 | pause(); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /cw04/zad1b/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc -Wall -ggdb 2 | 3 | out_file: main.c 4 | $(CC) -o out_file main.c 5 | 6 | test: out_file 7 | ./out_file 8 | 9 | clean: out_file 10 | rm out_file -------------------------------------------------------------------------------- /cw04/zad1b/Readme.md: -------------------------------------------------------------------------------- 1 | ## Zadanie 1 (25%) 2 | Napisz program wypisujący w pętli nieskończonej aktualną datę i godzinę. Po odebraniu sygnału SIGTSTP (CTRL+Z) program zatrzymuje się, wypisując komunikat "Oczekuję na CTRL+Z - kontynuacja albo CTR+C - zakończenie programu". Po ponownym wysłaniu SIGTSTP program powraca do pierwotnego wypisywania. 3 | 4 | Program powinien również obsługiwać sygnał SIGINT. Po jego odebraniu program wypisuje komunikat "Odebrano sygnał SIGINT" i kończy działanie. W kodzie programu, do przechwycenia sygnałów użyj zarówno funkcji signal, jak i sigaction (np. SIGINT odbierz za pomocą signal, a SIGTSTP za pomocą sigaction). 5 | 6 | Zrealizuj powyższe zadanie, tworząc program potomny, który będzie wywoływał jedną z funkcji z rodziny exec skrypt shellowy zawierający zapętlone systemowe polecenie date. Proces macierzysty będzie przychwytywał powyższe sygnały i przekazywał je do procesu potomnego, tj po otrzymaniu SIGTSTP kończy proces potomka, a jeśli ten został wcześniej zakończony, tworzy nowy, wznawiając działanie skryptu, a po otrzymaniu SIGINT kończy działanie potomka (jeśli ten jeszcze pracuje) oraz programu. 7 | 8 | -------------------------------------------------------------------------------- /cw04/zad1b/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | static int is_running = 1; 8 | 9 | static pid_t date_pid; 10 | 11 | void fork_script_print() { 12 | date_pid = fork(); 13 | if (date_pid == -1) { 14 | printf("Error with fork!\n"); 15 | } else if (date_pid > 0) { 16 | printf("\nfork PID: %d\n", date_pid); 17 | } else { 18 | execl("/bin/bash", "bash", "print_date.sh", NULL); 19 | exit(EXIT_FAILURE); 20 | } 21 | } 22 | 23 | void ctrl_c_handle_SIGINT(int sg) { 24 | printf("\nCtrl C pressed - end of program\n"); 25 | exit(sg); 26 | } 27 | 28 | void ctrl_z_handle_SIGTSTP(int sg) { 29 | if (is_running == 1) { 30 | printf( 31 | "\nCtrl Z pressed - continue with Ctrl Z or terminate with Ctrl " 32 | "C\n"); 33 | kill(date_pid, SIGKILL); 34 | } else { 35 | fork_script_print(); 36 | } 37 | 38 | is_running = 1 - is_running; 39 | } 40 | 41 | int main(int argc, char** argv) { 42 | signal(SIGINT, ctrl_c_handle_SIGINT); 43 | 44 | struct sigaction sigaction1; 45 | sigaction1.sa_handler = ctrl_z_handle_SIGTSTP; 46 | sigaction1.sa_flags = 0; 47 | sigaction(SIGTSTP, &sigaction1, NULL); 48 | 49 | fork_script_print(); 50 | 51 | while (1) { 52 | sleep(1); 53 | } 54 | 55 | return 0; 56 | } -------------------------------------------------------------------------------- /cw04/zad1b/print_date.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | while true 3 | do 4 | date 5 | sleep KolosEom 6 | done 7 | -------------------------------------------------------------------------------- /cw04/zad2/Makefile: -------------------------------------------------------------------------------- 1 | CC := gcc 2 | CFLAGS := -Wall -O3 -std=c99 3 | HEADERS := error.h 4 | SRC := monitor.c backup.c error.c 5 | NAME := monitor 6 | 7 | $(NAME): $(HEADERS) $(SRC) 8 | $(CC) $(CFLAGS) $(SRC) -o $(NAME) 9 | 10 | tester: tester.c 11 | $(CC) $(CFLAGS) tester.c -o tester 12 | 13 | clean: 14 | $(RM) -rf $(NAME) tester files archive 15 | 16 | test: $(NAME) tester 17 | mkdir -p "files" 18 | echo "files/file_1 1" > files/list 19 | echo "files/file_2 2" >> files/list 20 | echo "files/file_3 3" >> files/list 21 | echo "files/file_4 4" >> files/list 22 | 23 | ./tester files/file_1 1 3 16 & 24 | ./tester files/file_2 1 3 16 & 25 | ./tester files/file_3 1 3 16 & 26 | ./tester files/file_4 1 3 16 & 27 | 28 | ./monitor files/list 29 | pkill tester 30 | -------------------------------------------------------------------------------- /cw04/zad2/Readme.md: -------------------------------------------------------------------------------- 1 | ## Zadanie 2 (35%) 2 | Zmodyfikuj program 2 (monitor - wersję z alokowaniem pamięci) z poprzedniego zestawu tak, aby to program macierzysty był odpowiedzialny za zakończenie procesów potomnych. Nie ma ograniczenia czasowego dla działania programu. Po uruchomieniu programu proces macierzysty wypisuje listę plików przydzielonych do określonych procesów potomnych. Po utworzeniu procesów potomnych, które działają w nieskończonych pętlach proces macierzysty nie przechodził w stan uśpienia, czekając na zakończenie procesów, tylko obiera komendy od użytkownika: 3 | 4 | * LIST - program wypisuje listę procesów monitorujących pliki 5 | * STOP PID - program zatrzymuje (nie kończy) monitorowanie procesu o numerze PID. Można to zrealizować poprzez wysłanie do procesu potomnego sygnału SIGUSR1. Proces macierzysty po odebraniu sygnału zatrzymuje pętlę poprzez zmianę flagi. 6 | * STOP ALL - program zatrzymuje (nie kończy) monitorowanie wszystkich procesów potomnych 7 | * START PID - program wznawia monitorowanie procesu o numerze PID (również poprzez wysłanie sygnału i zmianę flagi). 8 | * START ALL - program wznawia działanie wszystkich procesów potomnych 9 | * END - program kończy działanie wszystkich procesów i wyświetla końcowy raport. 10 | 11 | **Zdefiniuj dodatkowo obsługę sygnału SIGINT, który będzie działał jak END, czyli wypisze raport końcowy.** -------------------------------------------------------------------------------- /cw04/zad2/backup.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "error.h" 10 | 11 | static char* backup_mem_buffer; 12 | static long backup_mem_buffer_size; 13 | 14 | char* get_backup_name(const char* filename) { 15 | time_t rawtime; 16 | struct tm* timeinfo; 17 | char* buffer = malloc(4096); 18 | 19 | time(&rawtime); 20 | timeinfo = localtime(&rawtime); 21 | 22 | char date[80]; 23 | strftime(date, sizeof(date), "%Y-%m-%d_%H-%M-%S", timeinfo); 24 | 25 | char filename_copy[4096]; 26 | strncpy(filename_copy, filename, sizeof(filename_copy) - 1); 27 | sprintf(buffer, "archive/%s_%s", basename(filename_copy), date); 28 | return buffer; 29 | } 30 | 31 | void backup_mem_read(const char* filename) { 32 | FILE* file = fopen(filename, "rb"); 33 | if (file == NULL) { 34 | perr("unable to open %s", filename); 35 | } 36 | 37 | fseek(file, 0, SEEK_END); 38 | backup_mem_buffer_size = ftell(file); 39 | backup_mem_buffer = realloc(backup_mem_buffer, backup_mem_buffer_size); 40 | rewind(file); 41 | fread(backup_mem_buffer, backup_mem_buffer_size, 1, file); 42 | fclose(file); 43 | } 44 | 45 | void backup_mem(const char* filename) { 46 | char* backup_name = get_backup_name(filename); 47 | 48 | FILE* file = fopen(backup_name, "wb"); 49 | if (file == NULL) { 50 | perr("unable to open %s", backup_name); 51 | } 52 | 53 | fwrite(backup_mem_buffer, backup_mem_buffer_size, 1, file); 54 | fclose(file); 55 | 56 | printf("PID: %d\t%s -> %s\n", getpid(), filename, backup_name); 57 | 58 | free(backup_name); 59 | backup_mem_read(filename); 60 | } 61 | -------------------------------------------------------------------------------- /cw04/zad2/backup.h: -------------------------------------------------------------------------------- 1 | #ifndef BACKUP_H 2 | #define BACKUP_H 3 | 4 | void backup_exec(const char* filename); 5 | void backup_mem(const char* filename); 6 | void backup_mem_read(const char* filename); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /cw04/zad2/error.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | void err(const char* format, ...) { 8 | va_list args; 9 | va_start(args, format); 10 | vfprintf(stderr, format, args); 11 | va_end(args); 12 | fputs("\n", stderr); 13 | exit(1); 14 | } 15 | 16 | void perr(const char* format, ...) { 17 | va_list args; 18 | va_start(args, format); 19 | vfprintf(stderr, format, args); 20 | fprintf(stderr, ": %s\n", strerror(errno)); 21 | exit(1); 22 | } 23 | -------------------------------------------------------------------------------- /cw04/zad2/error.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_ERROR_H 2 | #define LIST_ERROR_H 3 | 4 | void err(const char* format, ...); 5 | void perr(const char* format, ...); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /cw04/zad2/tester.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "error.h" 7 | 8 | int main(int argc, char* argv[]) { 9 | if (argc != 5) { 10 | err("usage: %s [file] [interval_min] [interval_max] [bytes]", argv[0]); 11 | } 12 | 13 | char* filename = argv[1]; 14 | 15 | char* end; 16 | int interval_min = strtol(argv[2], &end, 10); 17 | if (end == argv[2]) { 18 | err("cannot convert '%s' to a number", argv[2]); 19 | } 20 | 21 | int interval_max = strtol(argv[3], &end, 10); 22 | if (end == argv[3]) { 23 | err("cannot convert '%s' to a number", argv[3]); 24 | } 25 | 26 | int bytes = strtol(argv[4], &end, 10); 27 | if (end == argv[4]) { 28 | err("cannot convert '%s' to a number", argv[4]); 29 | } 30 | 31 | if (interval_min > interval_max) { 32 | err("interval_min should be lower than interval_max"); 33 | } 34 | 35 | srand(time(NULL)); 36 | 37 | FILE* f; 38 | char* random_buffer = malloc(bytes); 39 | time_t rawtime; 40 | struct tm* timeinfo; 41 | char date[80]; 42 | 43 | while (1) { 44 | int sleep_interval = 45 | interval_min + (rand() % (interval_max - interval_min + 1)); 46 | 47 | time(&rawtime); 48 | timeinfo = localtime(&rawtime); 49 | strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", timeinfo); 50 | 51 | f = fopen("/dev/urandom", "rb"); 52 | fread(random_buffer, bytes, 1, f); 53 | fclose(f); 54 | 55 | f = fopen(filename, "a"); 56 | fprintf(f, "pid: %d sleep: %d date: %s\nbytes: ", getpid(), 57 | sleep_interval, date); 58 | fwrite(random_buffer, bytes, 1, f); 59 | fputs("\n\n", f); 60 | fclose(f); 61 | 62 | sleep(sleep_interval); 63 | } 64 | 65 | free(random_buffer); 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /cw04/zad3a/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc -Wall -ggdb 2 | 3 | out_sender: sender.c 4 | $(CC) -o out_sender sender.c utils.c 5 | 6 | out_catcher: catcher.c 7 | $(CC) -o out_catcher catcher.c utils.c 8 | 9 | make catcher_and_sender: 10 | make out_sender 11 | make out_catcher 12 | 13 | clean: out_sender out_catcher 14 | rm out_sender 15 | rm out_catcher -------------------------------------------------------------------------------- /cw04/zad3a/Readme.md: -------------------------------------------------------------------------------- 1 | ## Zadanie 3 (40%) 2 | Napisz dwa programy: sender program wysyłający sygnały SIGUSR1 i catcher - program zliczający ilość odebranych sygnałów. Ilość sygnałów SIGUSR1 wysyłanych przez pierwszy program powinna być określana w parametrze wywołania tego programu. Program catcher jest uruchamiany najpierw, wypisuje swój numer PID i czeka na sygnały SIGUSR1 i SIGUSR2. Wszystkie pozostałe sygnały są blokowane. Program sender przyjmuje trzy parametry: PID procesu catcher, ilość sygnałów do wysłania i tryb wysłania sygnałów. 3 | 4 | Po transmisji wszystkich sygnałów SIGUSR1 sender powinien wysłać sygnał SIGUSR2, po otrzymaniu którego catcher wysyła do sendera tyle sygnałów SIGUSR1, ile sam ich otrzymał a „transmisję” kończy wysłaniem sygnału SIGUSR2, wypisaniem liczby odebranych sygnałów i zakończeniem działania. PID sendera catcher pobiera ze struktury SIGACTION po przechwyceniu od niego sygnału. Program sender po otrzymaniu sygnału SIGUSR2 wyświetla komunikat o ilości otrzymanych sygnałów SIGUSR1 oraz o tym, ile powinien ich otrzymać i kończy działanie. 5 | 6 | UWAGA! W żaden sposób nie opóźniamy wysyłania sygnałów, wszelkie "gubienie" sygnałów jest zjawiskiem naturalnym. 7 | 8 | **Wysyłanie sygnałów w obu programach należy wykonać w następujących trybach:** 9 | * KILL - za pomocą funkcji kill 10 | * SIGQUEUE - za pomocą funkcji sigqueue - wraz z przesłanym sygnałem catcher wysyła numer kolejnego odsyłanego sygnału, dzięki czemu sender wie, ile dokładnie catcher odebrał, a tym samym wysłał do niego sygnałów. Wypisz tę dodatkową informację w senderze. 11 | * SIGRT - zastępując SIGUSR1 i SIGUSR2 dwoma dowolnymi sygnałami czasu rzeczywistego wysyłanymi za pomocą kill. Jaka liczba sygnałów będzie teraz odebrana? 12 | 13 | Zmodyfikuj powyższe programy, dodając potwierdzenie odbioru sygnału po każdorazowym ich odebraniu przez program catcher. W tym celu, catcher wysyła do sendera sygnał SIGUSR1 informujący o odbiorze sygnału. Sender powinien wysłać kolejny sygnał dopiero po uzyskaniu tego potwierdzenia. Zapewnij rozwiązanie, w którym ilość sygnałów odebranych jest zgodna z ilością sygnałów wysłanych, i w którym nie dochodzi do zakleszczenia. (15%) 14 | -------------------------------------------------------------------------------- /cw04/zad3a/catcher.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "utils.h" 6 | 7 | static void kill_catch(int sig, siginfo_t* siginfo, void* context); 8 | 9 | static void queue_catch(int sig, siginfo_t* siginfo, void* context); 10 | 11 | static void rt_catch(int sig, siginfo_t* siginfo, void* context); 12 | 13 | int signal_counter = 0; 14 | 15 | int main(int argc, char** argv) { 16 | if (argc != 2) { 17 | printf("WRONG NUMBER OF ARGUMENTS! TRY AGAIN!\n"); 18 | return -1; 19 | } 20 | 21 | char* mode = argv[1]; 22 | 23 | if (strcmp(mode, "KILL") == 0) { 24 | initialize_signals(kill_catch); 25 | } else if (strcmp(mode, "SIGQUEUE") == 0) { 26 | initialize_signals(queue_catch); 27 | } else if (strcmp(mode, "SIGRT") == 0) { 28 | initialize_rt_signals(rt_catch); 29 | } else { 30 | printf("UNKNOWN MODE\n"); 31 | } 32 | 33 | printf("\nPID: %d\n", (int)getpid()); 34 | 35 | while (1) { 36 | pause(); 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | static void kill_catch(int sig, siginfo_t* siginfo, void* context) { 43 | if (sig == SIGUSR1) { 44 | ++signal_counter; 45 | } else { 46 | for (int i = 0; i < signal_counter; ++i) { 47 | if (kill(siginfo->si_pid, SIGUSR1) < 0) { 48 | printf("PROBLEM WITH KILL IN CATCHER\n"); 49 | } 50 | } 51 | 52 | if (kill(siginfo->si_pid, SIGUSR2) < 0) { 53 | printf("PROBLEM WITH KILL IN CATCHER\n"); 54 | } 55 | 56 | // printf("%d: SIGNALS\n", signal_counter); 57 | 58 | exit(0); 59 | } 60 | } 61 | 62 | static void queue_catch(int sig, siginfo_t* siginfo, void* context) { 63 | if (sig == SIGUSR1) { 64 | ++signal_counter; 65 | } else { 66 | for (int i = 0; i < signal_counter; ++i) { 67 | union sigval value = {i}; 68 | if (sigqueue(siginfo->si_pid, SIGUSR1, value) != 0) { 69 | printf("PROBLEM WITH SIGQUEUE METHOD\n"); 70 | } 71 | } 72 | if (kill(siginfo->si_pid, SIGUSR2) != 0) { 73 | printf("PROBLEM WITH KILL IN SIGQUEUE CATCH (SIGUSR2)\n"); 74 | } 75 | exit(0); 76 | } 77 | } 78 | 79 | static void rt_catch(int sig, siginfo_t* siginfo, void* context) { 80 | if (sig == SIGRTMIN) { 81 | ++signal_counter; 82 | } else { 83 | for (int i = 0; i < signal_counter; ++i) { 84 | if (kill(siginfo->si_pid, SIGRTMIN) != 0) { 85 | printf("PROBLEM WITH KILL IN RT CATCH\n"); 86 | } 87 | } 88 | 89 | if (kill(siginfo->si_pid, SIGRTMAX) != 0) { 90 | printf("PROBLEM WITH KILL IN RT CATCH (SIGRTMAX)\n"); 91 | } 92 | exit(0); 93 | } 94 | } -------------------------------------------------------------------------------- /cw04/zad3a/utils.c: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | void initialize_signals(void (*fun)(int, siginfo_t*, void*)) { 4 | sigset_t signals; 5 | 6 | if (sigfillset(&signals) == -1) { 7 | printf("PROBLEM WITH SIGFILLSET METHOD\n"); 8 | return; 9 | } 10 | 11 | sigdelset(&signals, SIGUSR1); 12 | sigdelset(&signals, SIGUSR2); 13 | 14 | if (sigprocmask(SIG_BLOCK, &signals, NULL) < 0) { 15 | printf("PROBLEM WITH SIGPROCMASK METHOD\n"); 16 | return; 17 | } 18 | 19 | if (sigemptyset(&signals) < 0) { 20 | printf("PROBLEM WITH SIGEMPTYSET METHOD\n"); 21 | return; 22 | } 23 | 24 | struct sigaction sigaction1; 25 | sigaction1.sa_sigaction = fun; 26 | sigaction1.sa_mask = signals; 27 | sigaction1.sa_flags = SA_SIGINFO; 28 | 29 | if (sigaction(SIGUSR1, &sigaction1, NULL) == -1 || 30 | sigaction(SIGUSR2, &sigaction1, NULL) == -1) { 31 | printf("PROBLEM WITH SIGACTION METHOD\n"); 32 | return; 33 | } 34 | } 35 | 36 | void initialize_rt_signals(void (*fun)(int, siginfo_t*, void*)) { 37 | sigset_t signals; 38 | 39 | if (sigfillset(&signals) == -1) { 40 | printf("PROBLEM WITH SIGFILLSET METHOD\n"); 41 | return; 42 | } 43 | 44 | sigdelset(&signals, SIGRTMIN); 45 | sigdelset(&signals, SIGRTMAX); 46 | 47 | if (sigprocmask(SIG_BLOCK, &signals, NULL) < 0) { 48 | printf("PROBLEM WITH SIGPROCMASK METHOD\n"); 49 | return; 50 | } 51 | 52 | if (sigemptyset(&signals) < 0) { 53 | printf("PROBLEM WITH SIGEMPTYSET METHOD\n"); 54 | return; 55 | } 56 | 57 | sigaddset(&signals, SIGRTMIN); 58 | sigaddset(&signals, SIGRTMAX); 59 | 60 | struct sigaction sigaction1; 61 | sigaction1.sa_sigaction = fun; 62 | sigaction1.sa_mask = signals; 63 | sigaction1.sa_flags = SA_SIGINFO; 64 | 65 | if (sigaction(SIGRTMIN, &sigaction1, NULL) == -1 || 66 | sigaction(SIGRTMAX, &sigaction1, NULL) == -1) { 67 | printf("PROBLEM WITH SIGACTION METHOD\n"); 68 | return; 69 | } 70 | } -------------------------------------------------------------------------------- /cw04/zad3a/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_UTILS_H 2 | #define SYSOPY_UTILS_H 3 | 4 | #include 5 | #include 6 | 7 | void initialize_signals(void (*fun)(int, siginfo_t*, void*)); 8 | 9 | void initialize_rt_signals(void (*fun)(int, siginfo_t*, void*)); 10 | 11 | #endif // SYSOPY_UTILS_H 12 | -------------------------------------------------------------------------------- /cw04/zad3b/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /cw04/zad3b/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /cw04/zad3b/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /cw04/zad3b/.idea/zad3b.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /cw04/zad3b/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc -Wall -ggdb 2 | 3 | out_sender: sender.c 4 | $(CC) -o out_sender sender.c utils.c 5 | 6 | out_catcher: catcher.c 7 | $(CC) -o out_catcher catcher.c utils.c 8 | 9 | make catcher_and_sender: 10 | make out_sender 11 | make out_catcher 12 | 13 | clean: out_sender out_catcher 14 | rm out_sender 15 | rm out_catcher -------------------------------------------------------------------------------- /cw04/zad3b/Readme.md: -------------------------------------------------------------------------------- 1 | ## Zadanie 3 (40%) 2 | Napisz dwa programy: sender program wysyłający sygnały SIGUSR1 i catcher - program zliczający ilość odebranych sygnałów. Ilość sygnałów SIGUSR1 wysyłanych przez pierwszy program powinna być określana w parametrze wywołania tego programu. Program catcher jest uruchamiany najpierw, wypisuje swój numer PID i czeka na sygnały SIGUSR1 i SIGUSR2. Wszystkie pozostałe sygnały są blokowane. Program sender przyjmuje trzy parametry: PID procesu catcher, ilość sygnałów do wysłania i tryb wysłania sygnałów. 3 | 4 | Po transmisji wszystkich sygnałów SIGUSR1 sender powinien wysłać sygnał SIGUSR2, po otrzymaniu którego catcher wysyła do sendera tyle sygnałów SIGUSR1, ile sam ich otrzymał a „transmisję” kończy wysłaniem sygnału SIGUSR2, wypisaniem liczby odebranych sygnałów i zakończeniem działania. PID sendera catcher pobiera ze struktury SIGACTION po przechwyceniu od niego sygnału. Program sender po otrzymaniu sygnału SIGUSR2 wyświetla komunikat o ilości otrzymanych sygnałów SIGUSR1 oraz o tym, ile powinien ich otrzymać i kończy działanie. 5 | 6 | UWAGA! W żaden sposób nie opóźniamy wysyłania sygnałów, wszelkie "gubienie" sygnałów jest zjawiskiem naturalnym. 7 | 8 | **Wysyłanie sygnałów w obu programach należy wykonać w następujących trybach:** 9 | * KILL - za pomocą funkcji kill 10 | * SIGQUEUE - za pomocą funkcji sigqueue - wraz z przesłanym sygnałem catcher wysyła numer kolejnego odsyłanego sygnału, dzięki czemu sender wie, ile dokładnie catcher odebrał, a tym samym wysłał do niego sygnałów. Wypisz tę dodatkową informację w senderze. 11 | * SIGRT - zastępując SIGUSR1 i SIGUSR2 dwoma dowolnymi sygnałami czasu rzeczywistego wysyłanymi za pomocą kill. Jaka liczba sygnałów będzie teraz odebrana? 12 | 13 | Zmodyfikuj powyższe programy, dodając potwierdzenie odbioru sygnału po każdorazowym ich odebraniu przez program catcher. W tym celu, catcher wysyła do sendera sygnał SIGUSR1 informujący o odbiorze sygnału. Sender powinien wysłać kolejny sygnał dopiero po uzyskaniu tego potwierdzenia. Zapewnij rozwiązanie, w którym ilość sygnałów odebranych jest zgodna z ilością sygnałów wysłanych, i w którym nie dochodzi do zakleszczenia. (15%) 14 | -------------------------------------------------------------------------------- /cw04/zad3b/catcher.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "utils.h" 6 | 7 | static void kill_catch(int sig, siginfo_t* siginfo, void* context); 8 | 9 | static void queue_catch(int sig, siginfo_t* siginfo, void* context); 10 | 11 | static void rt_catch(int sig, siginfo_t* siginfo, void* context); 12 | 13 | int signal_counter = 0; 14 | 15 | int main(int argc, char** argv) { 16 | if (argc != 2) { 17 | printf("WRONG NUMBER OF ARGUMENTS! TRY AGAIN!\n"); 18 | return -1; 19 | } 20 | 21 | char* mode = argv[1]; 22 | 23 | if (strcmp(mode, "KILL") == 0) { 24 | initialize_signals(kill_catch); 25 | } else if (strcmp(mode, "SIGQUEUE") == 0) { 26 | initialize_signals(queue_catch); 27 | } else if (strcmp(mode, "SIGRT") == 0) { 28 | initialize_rt_signals(rt_catch); 29 | } else { 30 | printf("UNKNOWN MODE\n"); 31 | } 32 | 33 | printf("\nPID: %d\n", (int)getpid()); 34 | 35 | while (1) { 36 | pause(); 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | static void kill_catch(int sig, siginfo_t* siginfo, void* context) { 43 | if (sig == SIGUSR1) { 44 | ++signal_counter; 45 | 46 | if (kill(siginfo->si_pid, SIGUSR1) < 0) { 47 | printf("PROBLEM WITH KILL IN CATCHER\n"); 48 | } 49 | 50 | } else { 51 | if (kill(siginfo->si_pid, SIGUSR2) < 0) { 52 | printf("PROBLEM WITH KILL IN CATCHER\n"); 53 | } 54 | exit(0); 55 | } 56 | } 57 | 58 | static void queue_catch(int sig, siginfo_t* siginfo, void* context) { 59 | if (sig == SIGUSR1) { 60 | ++signal_counter; 61 | 62 | if (sigqueue(siginfo->si_pid, SIGUSR1, siginfo->si_value) != 0) { 63 | printf("PROBLEM WITH SIGQUEUE METHOD\n"); 64 | } 65 | 66 | } else { 67 | if (kill(siginfo->si_pid, SIGUSR2) != 0) { 68 | printf("PROBLEM WITH KILL IN SIGQUEUE CATCH (SIGUSR2)\n"); 69 | } 70 | exit(0); 71 | } 72 | } 73 | 74 | static void rt_catch(int sig, siginfo_t* siginfo, void* context) { 75 | if (sig == SIGRTMIN) { 76 | ++signal_counter; 77 | 78 | if (kill(siginfo->si_pid, SIGRTMIN) != 0) { 79 | printf("PROBLEM WITH KILL IN RT CATCH\n"); 80 | } 81 | 82 | } else { 83 | if (kill(siginfo->si_pid, SIGRTMAX) != 0) { 84 | printf("PROBLEM WITH KILL IN RT CATCH (SIGRTMAX)\n"); 85 | } 86 | exit(0); 87 | } 88 | } -------------------------------------------------------------------------------- /cw04/zad3b/utils.c: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | void initialize_signals(void (*fun)(int, siginfo_t*, void*)) { 4 | sigset_t signals; 5 | 6 | if (sigfillset(&signals) == -1) { 7 | printf("PROBLEM WITH SIGFILLSET METHOD\n"); 8 | return; 9 | } 10 | 11 | sigdelset(&signals, SIGUSR1); 12 | sigdelset(&signals, SIGUSR2); 13 | 14 | if (sigprocmask(SIG_BLOCK, &signals, NULL) < 0) { 15 | printf("PROBLEM WITH SIGPROCMASK METHOD\n"); 16 | return; 17 | } 18 | 19 | if (sigemptyset(&signals) < 0) { 20 | printf("PROBLEM WITH SIGEMPTYSET METHOD\n"); 21 | return; 22 | } 23 | 24 | struct sigaction sigaction1; 25 | sigaction1.sa_sigaction = fun; 26 | sigaction1.sa_mask = signals; 27 | sigaction1.sa_flags = SA_SIGINFO; 28 | 29 | if (sigaction(SIGUSR1, &sigaction1, NULL) == -1 || 30 | sigaction(SIGUSR2, &sigaction1, NULL) == -1) { 31 | printf("PROBLEM WITH SIGACTION METHOD\n"); 32 | return; 33 | } 34 | } 35 | 36 | void initialize_rt_signals(void (*fun)(int, siginfo_t*, void*)) { 37 | sigset_t signals; 38 | 39 | if (sigfillset(&signals) == -1) { 40 | printf("PROBLEM WITH SIGFILLSET METHOD\n"); 41 | return; 42 | } 43 | 44 | sigdelset(&signals, SIGRTMIN); 45 | sigdelset(&signals, SIGRTMAX); 46 | 47 | if (sigprocmask(SIG_BLOCK, &signals, NULL) < 0) { 48 | printf("PROBLEM WITH SIGPROCMASK METHOD\n"); 49 | return; 50 | } 51 | 52 | if (sigemptyset(&signals) < 0) { 53 | printf("PROBLEM WITH SIGEMPTYSET METHOD\n"); 54 | return; 55 | } 56 | 57 | sigaddset(&signals, SIGRTMIN); 58 | sigaddset(&signals, SIGRTMAX); 59 | 60 | struct sigaction sigaction1; 61 | sigaction1.sa_sigaction = fun; 62 | sigaction1.sa_mask = signals; 63 | sigaction1.sa_flags = SA_SIGINFO; 64 | 65 | if (sigaction(SIGRTMIN, &sigaction1, NULL) == -1 || 66 | sigaction(SIGRTMAX, &sigaction1, NULL) == -1) { 67 | printf("PROBLEM WITH SIGACTION METHOD\n"); 68 | return; 69 | } 70 | } -------------------------------------------------------------------------------- /cw04/zad3b/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_UTILS_H 2 | #define SYSOPY_UTILS_H 3 | 4 | #include 5 | #include 6 | 7 | void initialize_signals(void (*fun)(int, siginfo_t*, void*)); 8 | 9 | void initialize_rt_signals(void (*fun)(int, siginfo_t*, void*)); 10 | 11 | #endif // SYSOPY_UTILS_H 12 | -------------------------------------------------------------------------------- /cw05/Readme.md: -------------------------------------------------------------------------------- 1 | # Zestaw 5 - Potoki nazwane i nienazwane 2 | ## Zadanie 1 3 | Napisz interpreter poleceń przechowywanych w pliku (sciezka do pliku to pierwszy argument wywolania programu). 4 | 5 | Polecenia w pliku przechowywane są w kolejnych liniach w postaci: 6 | 7 | prog1 arg1 ... argn1 | prog2 arg1 ... argn2 | ... | progN arg1 ... argnN 8 | 9 | Dla każdej takiej linii interpreter powinien uruchomić wszystkie N poleceń w osobnych procesach, zapewniając przy użyciu potoków nienazwanych oraz funkcji dup2, by wyjście standardowe procesu k było przekierowane do wejścia standardowego procesu (k+1). Można założyć ograniczenie górne na ilość obsługiwanych argumentów oraz ilość połączonych komend w pojedynczym poleceniu (co najmniej 5). Po uruchomieniu ciągu programów składających się na pojedczyne polecenie (linijkę) interpreter powinien oczekiwać na zakończenie wszystkich tych programów. 10 | 11 | __Uwaga: należy użyć pipe/fork/exec, nie popen__ 12 | 13 | # Zadanie 2 14 | Należy napisać dwa programy - master oraz slave - które będą komunikować się poprzez potok nazwany (kolejkę FIFO), do której ścieżkę będą dostawać jako argument wywołania. Do potoku pisać będzie wiele procesów wykonujących program slave, a czytał będzie z niej jeden proces master. 15 | 16 | Master przyjmuje jeden argument - ścieżkę do potoku nazwanego. Tworzy on ten potok nazwany, a następnie czyta kolejne linijki z potoku nazwanego i wypisuje je na ekran. 17 | 18 | Slave przyjmuje dwa argumenty - ścieżkę do potoku nazwanego i liczbę całkowitą N. Wykonuje następujące akcje: 19 | 20 | * otwiera potok nazwany 21 | * wypisuje swój PID na wyjście standardowe 22 | * N razy zapisuje do potoku nazwanego linijkę składającą się ze swojego PIDu oraz obecnej daty 23 | * datę należy wygenerować programem date uruchomionym przy użyciu funkcji popen 24 | * po każdym zapisie należy odczekać losową ilość czasu (np. 2-5 sekund) 25 | -------------------------------------------------------------------------------- /cw05/ancillary materials/Pipelines.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/cw05/ancillary materials/Pipelines.pdf -------------------------------------------------------------------------------- /cw05/ancillary materials/Pipelines_v2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/cw05/ancillary materials/Pipelines_v2.pdf -------------------------------------------------------------------------------- /cw05/lab/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc -Wall -ggdb 2 | 3 | out_file: main.c 4 | $(CC) -o out_file main.c 5 | 6 | test: 7 | ./out_file "ls -l" "wc -l" result.txt 8 | 9 | clean: result.txt 10 | rm -f result.txt -------------------------------------------------------------------------------- /cw05/lab/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | const int SIZE = 16384; 6 | 7 | int main(int argc, char** argv) { 8 | if (argc != 4) { 9 | printf("WRONG NUMBER OF ARGUMENTS!\n"); 10 | return -1; 11 | } 12 | 13 | char* first_command = argv[1]; 14 | char* second_command = argv[2]; 15 | char* out_filename = argv[3]; 16 | 17 | FILE* pipe_first = popen(first_command, "r"); 18 | if (pipe_first == NULL) { 19 | printf("PROBLEM WITH POPEN IN MAIN!\n"); 20 | return -1; 21 | } 22 | 23 | char buffer[SIZE]; 24 | 25 | if (fread(buffer, sizeof(char), SIZE, pipe_first) <= 0) { 26 | printf("PROBLEM WITH FREAD\n"); 27 | return -1; 28 | } 29 | 30 | pclose(pipe_first); 31 | 32 | int fd = open(out_filename, O_CREAT | O_WRONLY, 0644); 33 | 34 | if (fd == -1) { 35 | printf("PROBLEM WITH OPENING OUT FILE\n"); 36 | return -1; 37 | } 38 | 39 | dup2(fd, 1); 40 | dup2(fd, 2); 41 | 42 | FILE* pipe_second = popen(second_command, "w"); 43 | if (pipe_second == NULL) { 44 | printf("PROBLEM WITH POPEN IN MAIN\n"); 45 | return -1; 46 | } 47 | 48 | if (fwrite(buffer, sizeof(char), SIZE, pipe_second) <= 0) { 49 | printf("PROBLEM WITH FWRITE\n"); 50 | return -1; 51 | } 52 | 53 | pclose(pipe_second); 54 | close(fd); 55 | 56 | return 0; 57 | } -------------------------------------------------------------------------------- /cw05/lab/result.txt: -------------------------------------------------------------------------------- 1 | 8 2 | -------------------------------------------------------------------------------- /cw05/zad1/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc -Wall -ggdb 2 | 3 | out_file: main.c 4 | $(CC) -o out_file main.c 5 | 6 | run: main.c out_file 7 | ./out_file commands.txt 8 | 9 | clean: out_file 10 | rm -f out_file -------------------------------------------------------------------------------- /cw05/zad1/Readme.md: -------------------------------------------------------------------------------- 1 | ## Zadanie 1 2 | Napisz interpreter poleceń przechowywanych w pliku (sciezka do pliku to pierwszy argument wywolania programu). 3 | 4 | Polecenia w pliku przechowywane są w kolejnych liniach w postaci: 5 | 6 | prog1 arg1 ... argn1 | prog2 arg1 ... argn2 | ... | progN arg1 ... argnN 7 | 8 | Dla każdej takiej linii interpreter powinien uruchomić wszystkie N poleceń w osobnych procesach, zapewniając przy użyciu potoków nienazwanych oraz funkcji dup2, by wyjście standardowe procesu k było przekierowane do wejścia standardowego procesu (k+1). Można założyć ograniczenie górne na ilość obsługiwanych argumentów oraz ilość połączonych komend w pojedynczym poleceniu (co najmniej 5). Po uruchomieniu ciągu programów składających się na pojedczyne polecenie (linijkę) interpreter powinien oczekiwać na zakończenie wszystkich tych programów. 9 | 10 | __Uwaga: należy użyć pipe/fork/exec, nie popen__ -------------------------------------------------------------------------------- /cw05/zad1/commands.txt: -------------------------------------------------------------------------------- 1 | ls -la | wc -l 2 | ps -aux | grep root | wc -l 3 | cat /etc/passwd | head -5 -------------------------------------------------------------------------------- /cw05/zad2/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc -Wall -ggdb 2 | 3 | out_slave: slave.c 4 | $(CC) -o out_slave slave.c utils.c 5 | 6 | out_master: master.c 7 | $(CC) -o out_master master.c utils.c 8 | 9 | master_and_slave: 10 | make out_master 11 | make out_slave 12 | 13 | run_slave: out_slave 14 | ./out_slave pipe_file 3 15 | 16 | run_master: out_master 17 | ./out_master pipe_file 18 | 19 | clean: 20 | rm -f out_master 21 | rm -f out_slave 22 | rm -f pipe_file -------------------------------------------------------------------------------- /cw05/zad2/Readme.md: -------------------------------------------------------------------------------- 1 | # Zadanie 2 2 | Należy napisać dwa programy - master oraz slave - które będą komunikować się poprzez potok nazwany (kolejkę FIFO), do której ścieżkę będą dostawać jako argument wywołania. Do potoku pisać będzie wiele procesów wykonujących program slave, a czytał będzie z niej jeden proces master. 3 | 4 | Master przyjmuje jeden argument - ścieżkę do potoku nazwanego. Tworzy on ten potok nazwany, a następnie czyta kolejne linijki z potoku nazwanego i wypisuje je na ekran. 5 | 6 | Slave przyjmuje dwa argumenty - ścieżkę do potoku nazwanego i liczbę całkowitą N. Wykonuje następujące akcje: 7 | 8 | * otwiera potok nazwany 9 | * wypisuje swój PID na wyjście standardowe 10 | * N razy zapisuje do potoku nazwanego linijkę składającą się ze swojego PIDu oraz obecnej daty 11 | * datę należy wygenerować programem date uruchomionym przy użyciu funkcji popen 12 | * po każdym zapisie należy odczekać losową ilość czasu (np. 2-5 sekund) 13 | -------------------------------------------------------------------------------- /cw05/zad2/master.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "utils.h" 5 | 6 | int main(int argc, char** argv) { 7 | if (argc != 2) { 8 | print_error_message_and_exit("WRONG NUMBER OF ARGUMENTS! TRY AGAIN"); 9 | } 10 | 11 | char* named_pipe_path = argv[1]; 12 | 13 | if (mkfifo(named_pipe_path, 0777)) { 14 | print_error_message("PROBLEM WITH CREATING FIFO"); 15 | } 16 | 17 | int named_pipe_file = open(named_pipe_path, O_RDONLY); 18 | 19 | if (named_pipe_file < 0) { 20 | print_error_message("PROBLEM WITH READING FILE"); 21 | } 22 | 23 | char line[BUFFER_SIZE]; 24 | while (1) { 25 | while (read(named_pipe_file, line, BUFFER_SIZE) > 0) { 26 | printf("%s\n", line); 27 | } 28 | } 29 | 30 | close(named_pipe_file); 31 | } -------------------------------------------------------------------------------- /cw05/zad2/slave.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "utils.h" 8 | 9 | int main(int argc, char** argv) { 10 | if (argc != 3) { 11 | print_error_message_and_exit("WRONG NUMBER OF ARGUMENTS! TRY AGAIN"); 12 | } 13 | 14 | srand((unsigned)time(NULL)); 15 | 16 | char* end_ptr = NULL; 17 | char* named_pipe_path = argv[1]; 18 | long number_of_savings = strtol(argv[2], &end_ptr, 10); 19 | 20 | int named_pipe_file = open(named_pipe_path, O_WRONLY); 21 | 22 | printf("THE PID OF CURRENT SLAVE: %d\n", getpid()); 23 | 24 | char date_buffer[BUFFER_SIZE]; 25 | 26 | int WHOLE_SIZE = 2 * BUFFER_SIZE; 27 | char whole_buffer[WHOLE_SIZE]; 28 | 29 | for (int i = 0; i < number_of_savings; ++i) { 30 | FILE* date_file = popen("date", "r"); 31 | if (fread(date_buffer, sizeof(char), BUFFER_SIZE, date_file) < 1) { 32 | print_error_message("SOME PROBLEMS WITH GETTING DATA WITH POPEN"); 33 | } 34 | fclose(date_file); 35 | 36 | snprintf(whole_buffer, WHOLE_SIZE, 37 | "CURRENT PID OF SLAVE: %d, DATE: %s\n", getpid(), date_buffer); 38 | if (write(named_pipe_file, whole_buffer, strlen(whole_buffer)) < 1) { 39 | print_error_message("SOME PROBLEMS WITH WRITING TO PIPE FILE"); 40 | } 41 | 42 | sleep(2 + rand() % 3); 43 | } 44 | 45 | close(named_pipe_file); 46 | } -------------------------------------------------------------------------------- /cw05/zad2/utils.c: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | void print_error_message(char* error_message) { 4 | printf("%s\n", error_message); 5 | } 6 | 7 | void print_error_message_and_exit(char* error_message) { 8 | printf("%s\n", error_message); 9 | exit(EXIT_FAILURE); 10 | } -------------------------------------------------------------------------------- /cw05/zad2/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_UTILS_H 2 | #define SYSOPY_UTILS_H 3 | 4 | #include 5 | #include 6 | 7 | #define BUFFER_SIZE 256 8 | 9 | void print_error_message(char* error_message); 10 | 11 | void print_error_message_and_exit(char* error_message); 12 | 13 | #endif // SYSOPY_UTILS_H 14 | -------------------------------------------------------------------------------- /cw06/ancillary_materials/MessageQueues.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/cw06/ancillary_materials/MessageQueues.pdf -------------------------------------------------------------------------------- /cw06/zad1/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc -Wall -ggdb 2 | 3 | all: server client 4 | 5 | 6 | client: client.c 7 | $(CC) client.c -o ./client 8 | 9 | server: server.c 10 | $(CC) server.c -o ./server 11 | 12 | test_server: server.c 13 | gcc ./server.c -ggdb -Wall -0O -o ./test_server 14 | 15 | test_client: client.c 16 | gcc ./client.c -ggdb -Wall -O0 -o ./test_client 17 | 18 | clean: 19 | rm -rf *.o server test_server client test_client 20 | -------------------------------------------------------------------------------- /cw06/zad1/commands.txt: -------------------------------------------------------------------------------- 1 | LIST 2 | ECHO echo_test123 3 | FRIENDS 1,2 4 | 2FRIENDS message_to_friends1 5 | DEL 1 6 | 2FRIENDS message_to_friends2 7 | DEL 2 8 | 2FRIENDS message_to_friends3 9 | ADD 1 10 | ADD 2 11 | 2FRIENDS message_to_friends4 12 | FRIENDS 13 | 2FRIENDS message_to_friends5 14 | 2ALL to_all 15 | 2ONE 1 do_1 16 | 2ONE 2 do_2 -------------------------------------------------------------------------------- /cw06/zad1/commands2.txt: -------------------------------------------------------------------------------- 1 | LIST 2 | ECHO echo_test123 3 | FRIENDS 1,2 4 | 2FRIENDS message_to_friends1 5 | DEL 1 6 | 2FRIENDS message_to_friends2 7 | DEL 2 8 | 2FRIENDS message_to_friends3 9 | ADD 1 10 | ADD 2 11 | 2FRIENDS message_to_friends4 12 | FRIENDS 13 | 2FRIENDS message_to_friends5 14 | 2ALL to_all 15 | 2ONE 1 do_1 16 | 2ONE 2 do_2 17 | STOP -------------------------------------------------------------------------------- /cw06/zad2/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc -Wall -ggdb 2 | 3 | all: server client 4 | 5 | server: server.c 6 | $(CC) server.c -o server -lrt 7 | 8 | client: client.c 9 | $(CC) client.c -o client -lrt 10 | 11 | clean: 12 | rm -rf *.o server test_server client test_client -------------------------------------------------------------------------------- /cw06/zad2/Readme.md: -------------------------------------------------------------------------------- 1 | #### Odpalanie 2 | Kompilacja: 3 | ```bash 4 | make all 5 | ``` 6 | odpalenie serwera w jednym terminalu: 7 | ```bash 8 | ./server 9 | ``` 10 | 11 | odpalenie różnych klientów w różnych terminalach: 12 | ```bash 13 | ./client 14 | ``` 15 | w kazdym terminalu 16 | 17 | wczytywanie z pliku w kliencie: 18 | ```bash 19 | READ scieżka_do_pliku_z_komendami 20 | ``` 21 | 22 | komendy: 23 | ```bash 24 | ECHO string 25 | 26 | LIST 27 | 28 | FRIENDS lista_id_klientów 29 | 30 | 2ALL string 31 | 32 | 2FRIENDS string 33 | 34 | 2ONE id_klienta string 35 | 36 | STOP 37 | ``` 38 | 39 | ## Zadanie 2. Prosty chat - POSIX (50%) 40 | ##### Zrealizuj zadanie analogiczne do Zadania 1, wykorzystując kolejki komunikatów POSIX. 41 | 42 | Kolejka klienta powinna mieć losową nazwę zgodną z wymaganiami stawianymi przez POSIX. 43 | 44 | Na typ komunikatu można zarezerwować pierwszy bajt jego treści. 45 | 46 | Obsługa zamykania kolejek analogiczna jak w zadaniu 1, z tym, że aby można było usunąć kolejkę, 47 | wszystkie procesy powinny najpierw ją zamknąć. 48 | 49 | Przed zakończeniem pracy klient wysyła do serwera komunikat informujący, 50 | że serwer powinien zamknąć po swojej stronie kolejkę klienta. 51 | 52 | Następnie klient zamyka i usuwa swoją kolejkę. 53 | 54 | Serwer przed zakończeniem pracy zamyka wszystkie otwarte kolejki, 55 | informuje klientów, aby usunęli swoje kolejki oraz zamknęli kolejkę serwera i usuwa kolejkę, którą utworzył. 56 | 57 | 58 | -------------------------------------------------------------------------------- /cw06/zad2/commands.txt: -------------------------------------------------------------------------------- 1 | LIST 2 | ECHO echo_test123 3 | FRIENDS 1,2 4 | 2FRIENDS message_to_friends1 5 | DEL 1 6 | 2FRIENDS message_to_friends2 7 | DEL 2 8 | 2FRIENDS message_to_friends3 9 | ADD 1 10 | ADD 2 11 | 2FRIENDS message_to_friends4 12 | FRIENDS 13 | 2FRIENDS message_to_friends5 14 | 2ALL to_all 15 | 2ONE 1 do_1 16 | 2ONE 2 do_2 -------------------------------------------------------------------------------- /cw06/zad2/commands2.txt: -------------------------------------------------------------------------------- 1 | LIST 2 | ECHO echo_test123 3 | FRIENDS 1,2 4 | 2FRIENDS message_to_friends1 5 | DEL 1 6 | 2FRIENDS message_to_friends2 7 | DEL 2 8 | 2FRIENDS message_to_friends3 9 | ADD 1 10 | ADD 2 11 | 2FRIENDS message_to_friends4 12 | FRIENDS 13 | 2FRIENDS message_to_friends5 14 | 2ALL to_all 15 | 2ONE 1 do_1 16 | 2ONE 2 do_2 17 | STOP -------------------------------------------------------------------------------- /cw07/ancillary_materials/Semaphores.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/cw07/ancillary_materials/Semaphores.pdf -------------------------------------------------------------------------------- /cw07/lab/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define SIZE 32 9 | 10 | #define MEMORY_NAME "/memory" 11 | 12 | int main(int argc, char** argv) { 13 | int fd = shm_open(MEMORY_NAME, O_RDWR | O_CREAT | O_EXCL, 0666); 14 | 15 | if (fd == -1) { 16 | printf("ERROR while creating shared memory!\n"); 17 | } 18 | 19 | if (ftruncate(fd, SIZE) == -1) { 20 | printf("ERROR while ftruncate\n"); 21 | } 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /cw07/zad1/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | 3 | FLAGS = -Wall -O3 -std=c99 4 | 5 | HEADERS = shared.h conveyor_belt.h pack.h error.h utils.h 6 | 7 | SRC_FILES = systemv.c conveyor_belt.c pack.c error.c utils.c 8 | 9 | .DEFAULT: all 10 | 11 | all: trucker loader spawner 12 | 13 | trucker: $(SRC_FILES) $(HEADERS) trucker.c 14 | $(CC) $(FLAGS) $(SRC_FILES) trucker.c -o trucker 15 | 16 | loader: $(SRC_FILES) $(HEADERS) loader.c 17 | $(CC) $(FLAGS) $(SRC_FILES) loader.c -o loader 18 | 19 | spawner: $(SRC_FILES) $(HEADERS) spawner.c 20 | $(CC) $(FLAGS) $(SRC_FILES) spawner.c -o spawner 21 | 22 | 23 | run_trucker: trucker 24 | ./trucker 20 5 10 25 | 26 | run_spawner: spawner 27 | ./spawner 5 5 28 | 29 | 30 | clean: 31 | rm -f trucker loader spawner -------------------------------------------------------------------------------- /cw07/zad1/conveyor_belt.c: -------------------------------------------------------------------------------- 1 | #include "conveyor_belt.h" 2 | #include "shared.h" 3 | 4 | conveyor_belt_t new_queue(int capacity, int max_weight, int sem_key) { 5 | conveyor_belt_t cb; 6 | cb.size = 0; 7 | cb.capacity = capacity; 8 | cb.weight = 0; 9 | cb.max_weight = max_weight; 10 | cb.head = 0; 11 | cb.tail = capacity - 1; 12 | cb.sem_key = sem_key; 13 | 14 | return cb; 15 | } 16 | 17 | int enqueue(conveyor_belt_t* cb, sem_id_t sem, pack_t pack) { 18 | if (cb->weight + pack.weight > cb->max_weight) { 19 | return -2; 20 | } 21 | 22 | int result; 23 | 24 | lock_semaphore(sem); 25 | 26 | if (cb->size == cb->capacity) { 27 | result = -1; 28 | } else { 29 | cb->tail = (cb->tail + 1) % cb->capacity; 30 | cb->array[cb->tail] = pack; 31 | cb->size += 1; 32 | cb->weight += pack.weight; 33 | result = 0; 34 | } 35 | 36 | unlock_semaphore(sem); 37 | 38 | return result; 39 | } 40 | 41 | pack_t* dequeue(conveyor_belt_t* cb, sem_id_t sem, pack_t* pack) { 42 | lock_semaphore(sem); 43 | 44 | if (pack == NULL || cb->size == 0) { 45 | pack = NULL; 46 | } else { 47 | *pack = cb->array[cb->head]; 48 | cb->head = (cb->head + 1) % cb->capacity; 49 | cb->size -= 1; 50 | cb->weight -= pack->weight; 51 | } 52 | 53 | unlock_semaphore(sem); 54 | 55 | return pack; 56 | } -------------------------------------------------------------------------------- /cw07/zad1/conveyor_belt.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_CONVEYOR_BELT_H 2 | #define SYSOPY_CONVEYOR_BELT_H 3 | 4 | #include 5 | #include "pack.h" 6 | #include "shared.h" 7 | 8 | #define MAX_CAPACITY 512 9 | 10 | #define CB_SIZE sizeof(conveyor_belt_t) 11 | 12 | typedef struct conveyor_belt_t { 13 | int size; 14 | int capacity; 15 | 16 | int weight; 17 | int max_weight; 18 | 19 | int head; 20 | int tail; 21 | 22 | int sem_key; 23 | 24 | pack_t array[MAX_CAPACITY]; 25 | } conveyor_belt_t; 26 | 27 | conveyor_belt_t new_queue(int capacity, int max_weight, int sem_key); 28 | 29 | int enqueue(conveyor_belt_t* cb, sem_id_t sem, pack_t item); 30 | 31 | pack_t* dequeue(conveyor_belt_t* cb, sem_id_t sem, pack_t* item); 32 | 33 | #endif // SYSOPY_CONVEYOR_BELT_H 34 | -------------------------------------------------------------------------------- /cw07/zad1/error.c: -------------------------------------------------------------------------------- 1 | #include "error.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | void print_coloured_message(char* message, char* colour) { 8 | printf("%s%s" RESET "\n", colour, message); 9 | } 10 | 11 | void print_error(char* message) { 12 | print_coloured_message(message, RED); 13 | fprintf(stderr, ": %s\n", strerror(errno)); 14 | exit(1); 15 | } 16 | -------------------------------------------------------------------------------- /cw07/zad1/error.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_ERROR_H 2 | #define SYSOPY_ERROR_H 3 | 4 | #define RED "\x1B[31m" 5 | #define GREEN "\x1B[32m" 6 | #define YELLOW "\x1B[33m" 7 | #define BLUE "\x1B[34m" 8 | #define MAGENTA "\x1B[35m" 9 | #define CYAN "\x1B[36m" 10 | #define WHITE "\x1B[37m" 11 | #define BRIGHT_RED "\x1B[91m" 12 | #define BRIGHT_GREEN "\x1B[92m" 13 | #define BRIGHT_YELLOW "\x1B[93m" 14 | #define BRIGHT_BLUE "\x1B[94m" 15 | #define BRIGHT_MAGENTA "\x1B[95m" 16 | #define BRIGHT_CYAN "\x1B[96m" 17 | #define BRIGHT_WHITE "\x1B[97m" 18 | 19 | #define RESET "\x1B[0m" 20 | 21 | void print_coloured_message(char* message, char* colour); 22 | 23 | void print_error(char* message); 24 | 25 | #endif // SYSOPY_ERROR_H 26 | -------------------------------------------------------------------------------- /cw07/zad1/pack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "pack.h" 5 | 6 | pack_t new_pack(int weight) { 7 | pack_t pack; 8 | pack.weight = weight; 9 | pack.pid = getpid(); 10 | gettimeofday(&pack.timestamp, NULL); 11 | 12 | return pack; 13 | } -------------------------------------------------------------------------------- /cw07/zad1/pack.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_PACK_H 2 | #define SYSOPY_PACK_H 3 | 4 | #include 5 | 6 | typedef struct pack_t { 7 | int weight; 8 | int pid; 9 | struct timeval timestamp; 10 | } pack_t; 11 | 12 | pack_t new_pack(int weight); 13 | 14 | #endif // SYSOPY_PACK_H 15 | -------------------------------------------------------------------------------- /cw07/zad1/shared.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_SHARED_H 2 | #define SYSOPY_SHARED_H 3 | 4 | #include 5 | #include 6 | 7 | /* ################################################################################################################## 8 | */ 9 | 10 | #ifdef POSIX 11 | typedef sem_t* sem_id_t; 12 | #else 13 | typedef int sem_id_t; 14 | #endif 15 | 16 | /* ################################################################################################################## 17 | */ 18 | 19 | int create_shared_mem(int key, size_t size); 20 | 21 | int open_shared_mem(int key, size_t size); 22 | 23 | void* map_shared_mem(int id, size_t size); 24 | 25 | void unmap_shared_mem(void* ptr, size_t size); 26 | 27 | void remove_shared_mem(int key, int id); 28 | 29 | /* ################################################################################################################## 30 | */ 31 | 32 | sem_id_t create_semaphore(int key); 33 | 34 | sem_id_t open_semaphore(int key); 35 | 36 | void lock_semaphore(sem_id_t id); 37 | 38 | void unlock_semaphore(sem_id_t id); 39 | 40 | void close_semaphore(sem_id_t id); 41 | 42 | void remove_semaphore(int key, sem_id_t id); 43 | 44 | /* ################################################################################################################## 45 | */ 46 | 47 | #endif // SYSOPY_SHARED_H 48 | -------------------------------------------------------------------------------- /cw07/zad1/spawner.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "error.h" 8 | 9 | int main(int argc, char** argv) { 10 | if (argc != 3 && argc != 4) { 11 | print_coloured_message( 12 | "invalid arguments given - necessary arguments: workers, " 13 | "max_weight, " 14 | "(cycles)", 15 | RED); 16 | } 17 | 18 | int workers; 19 | int max_weight; 20 | 21 | if (sscanf(argv[1], "%d", &workers) != 1 || 22 | sscanf(argv[2], "%d", &max_weight) != 1) { 23 | print_coloured_message("passed arguments are invalid", RED); 24 | } 25 | 26 | int cycles = 0; 27 | 28 | if (argc == 4) { 29 | if (sscanf(argv[3], "%d", &cycles) != 1) { 30 | print_coloured_message("passed arguments are invalid", RED); 31 | } 32 | } 33 | 34 | srand(time(NULL)); 35 | 36 | char cycles_arr[16]; 37 | sprintf(cycles_arr, "%d", cycles); 38 | 39 | char weight_arr[16]; 40 | 41 | for (int i = 0; i < workers; ++i) { 42 | sprintf(weight_arr, "%d", rand() % max_weight + 1); 43 | 44 | switch (fork()) { 45 | case -1: 46 | print_error("problem with fork"); 47 | break; 48 | case 0: 49 | execl("./loader", "./loader", weight_arr, cycles_arr, 50 | (char*)NULL); 51 | print_error("error while executing loader program"); 52 | break; 53 | } 54 | } 55 | 56 | int status; 57 | 58 | for (int i = 0; i < workers; ++i) { 59 | wait(&status); 60 | 61 | char loader_finished_buffer[1024]; 62 | 63 | sprintf(loader_finished_buffer, 64 | "loader %d finished with exit status: %d", i, 65 | WEXITSTATUS(status)); 66 | 67 | print_coloured_message(loader_finished_buffer, BLUE); 68 | } 69 | 70 | return 0; 71 | } -------------------------------------------------------------------------------- /cw07/zad1/utils.c: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | #include 3 | #include 4 | #include 5 | 6 | int get_trucker_key() { 7 | return ftok(getenv("HOME"), 2137); 8 | } 9 | 10 | int get_queue_key() { 11 | return ftok(getenv("HOME"), 1337); 12 | } 13 | 14 | long get_timestamp() { 15 | struct timeval timestamp; 16 | gettimeofday(×tamp, NULL); 17 | 18 | return timestamp.tv_sec * MILLION + timestamp.tv_usec; 19 | } -------------------------------------------------------------------------------- /cw07/zad1/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_UTILS_H 2 | #define SYSOPY_UTILS_H 3 | 4 | #define forever while (1) 5 | 6 | #define MILLION 1000000 7 | 8 | int get_trucker_key(); 9 | 10 | int get_queue_key(); 11 | 12 | long get_timestamp(); 13 | 14 | #endif // SYSOPY_UTILS_H -------------------------------------------------------------------------------- /cw07/zad2/Makefile: -------------------------------------------------------------------------------- 1 | D = ../zad1 2 | 3 | CC = gcc 4 | 5 | FLAGS = -Wall -O3 -std=c99 -I$(D) -DPOSIX 6 | 7 | OTHER_FLAGS = -lrt -pthread 8 | 9 | HEADERS = $(D)/shared.h $(D)/conveyor_belt.h $(D)/pack.h $(D)/error.h $(D)/utils.h 10 | 11 | SRC_FILES = posix.c $(D)/conveyor_belt.c $(D)/pack.c $(D)/error.c $(D)/utils.c 12 | 13 | .DEFAULT: all 14 | 15 | all: trucker loader spawner 16 | 17 | trucker: $(SRC_FILES) $(HEADERS) $(D)/trucker.c 18 | $(CC) $(FLAGS) $(SRC_FILES) $(D)/trucker.c -o trucker $(OTHER_FLAGS) 19 | 20 | loader: $(SRC_FILES) $(HEADERS) $(D)/loader.c 21 | $(CC) $(FLAGS) $(SRC_FILES) $(D)/loader.c -o loader $(OTHER_FLAGS) 22 | 23 | spawner: $(SRC_FILES) $(HEADERS) $(D)/spawner.c 24 | $(CC) $(FLAGS) $(SRC_FILES) $(D)/spawner.c -o spawner $(OTHER_FLAGS) 25 | 26 | 27 | run_trucker: trucker 28 | ./trucker 20 5 10 29 | 30 | run_spawner: spawner 31 | ./spawner 5 5 32 | 33 | 34 | clean: 35 | rm -f trucker loader spawner -------------------------------------------------------------------------------- /cw08/Readme.md: -------------------------------------------------------------------------------- 1 | ## JAKUB DYBCZAK TO KOZAK ABSOLUTNY TAK SAMO JAK PIOTR SZCZYGIEŁ, NIE WIEM KTÓRY LEPSZY 2 | 3 | ![image](https://user-images.githubusercontent.com/29823037/58035194-8dd58600-7b28-11e9-88a5-df73efadd45b.png) 4 | 5 | ![image](https://user-images.githubusercontent.com/29823037/58035240-a34ab000-7b28-11e9-8438-7e606fc5f976.png) 6 | -------------------------------------------------------------------------------- /cw08/ancillary_materials/Threads.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/cw08/ancillary_materials/Threads.pdf -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | CFLAGS = -Wall 3 | HEADERS = filter.h gaussian_filter.h image.h utils.h errors.h 4 | SRC = filter.c image.c utils.c errors.c 5 | 6 | .PHONY: clean 7 | 8 | all : main filters_generator 9 | 10 | main : $(SRC) $(HEADERS) main.c 11 | $(CC) $(CFLAGS) $(SRC) main.c -o main -lm -pthread 12 | 13 | filters_generator : $(SRC) $(HEADERS) filters_generator.c gaussian_filter.h gaussian_filter.c 14 | $(CC) $(CFLAGS) $(SRC) filters_generator.c gaussian_filter.c -o filters_generator -lm -pthread 15 | 16 | test : $(SRC) $(HEADERS) test.c 17 | $(CC) $(CFLAGS) $(SRC) test.c -o test -lm -pthread 18 | 19 | clean : 20 | rm -f main 21 | rm -f filters_generator 22 | rm -rf generated_filters/* 23 | rm -rf images_out/* 24 | rm -f test 25 | -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/Readme.md: -------------------------------------------------------------------------------- 1 | ![image](https://user-images.githubusercontent.com/29823037/58035194-8dd58600-7b28-11e9-88a5-df73efadd45b.png) 2 | 3 | ![image](https://user-images.githubusercontent.com/29823037/58035240-a34ab000-7b28-11e9-8438-7e606fc5f976.png) 4 | -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/errors.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void pdie(char* message, int exit_code) { 5 | perror(message); 6 | exit(exit_code); 7 | } 8 | 9 | void die(char* message, int exit_code) { 10 | fprintf(stderr, "%s\n", message); 11 | exit(exit_code); 12 | } 13 | 14 | int perr(char* message, int return_code) { 15 | perror(message); 16 | return return_code; 17 | } 18 | 19 | int err(char* message, int return_code) { 20 | fprintf(stderr, "%s\n", message); 21 | return return_code; 22 | } 23 | 24 | void outperr(char* message) { 25 | perror(message); 26 | } 27 | 28 | void outerr(char* message) { 29 | fprintf(stderr, "%s\n", message); 30 | } -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/errors.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_ERRORS_H 2 | #define SYSOPY_ERRORS_H 3 | 4 | void pdie(char* message, int exit_code); 5 | 6 | void die(char* message, int exit_code); 7 | 8 | int perr(char* message, int return_code); 9 | 10 | int err(char* message, int return_code); 11 | 12 | void outerr(char* message); 13 | 14 | void outperr(char* message); 15 | 16 | #endif // SYSOPY_ERRORS_H 17 | -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/filter.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_FILTER_H 2 | #define SYSOPY_FILTER_H 3 | 4 | #include "image.h" 5 | 6 | #define EDGE_EXTEND (edge_mode_t)1 7 | 8 | typedef int edge_mode_t; 9 | 10 | typedef struct filter_t { 11 | double* array; 12 | int size; 13 | int normalized; 14 | } filter_t; 15 | 16 | int filter_allocate(filter_t* filter, int size); 17 | 18 | int filter_deallocate(filter_t* filter); 19 | 20 | int filter_load(const char* path, filter_t* out); 21 | 22 | int filter_save(const char* path, filter_t* filter); 23 | 24 | int filter_normalize(filter_t* filter); 25 | 26 | int filter_apply(filter_t* filter, 27 | img_t* image_in, 28 | img_t* image_out, 29 | int x, 30 | int y, 31 | edge_mode_t edge_mode); 32 | 33 | #endif // SYSOPY_FILTER_H 34 | -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/filters/edge_detection.txt: -------------------------------------------------------------------------------- 1 | # edge detection filter 2 | # http://aishack.in/tutorials/image-convolution-examples/ 3 | 3 4 | -1 -1 -1 5 | -1 8 -1 6 | -1 -1 -1 -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/filters/emboss.txt: -------------------------------------------------------------------------------- 1 | # emboss 2 | # http://setosa.io/ev/image-kernels/ 3 | 3 4 | -2 -1 0 5 | -1 1 1 6 | 0 1 2 -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/filters/gaussian_blur.txt: -------------------------------------------------------------------------------- 1 | # Gaussian blur 5x5 2 | # https://en.wikipedia.org/wiki/Kernel_(image_processing) 3 | 5 4 | 1 4 6 4 1 5 | 4 16 24 16 4 6 | 6 24 36 24 6 7 | 4 16 24 16 4 8 | 1 4 6 4 1 -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/filters/none.txt: -------------------------------------------------------------------------------- 1 | # no effect 2 | 3 3 | 0 0 0 4 | 0 1 0 5 | 0 0 0 -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/filters/sharpen.txt: -------------------------------------------------------------------------------- 1 | # sharpen 2 | # https://en.wikipedia.org/wiki/Kernel_(image_processing) 3 | 3 4 | 0 -1 0 5 | -1 5 -1 6 | 0 -1 0 -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/filters/simple_blur.txt: -------------------------------------------------------------------------------- 1 | # simple blur 2 | 3 3 | 1 1 1 4 | 1 1 1 5 | 1 1 1 -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/filters_generator.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "filter.h" 5 | #include "gaussian_filter.h" 6 | 7 | int main() { 8 | char buffer[255]; 9 | 10 | for (int i = 3; i <= 65; i += 2) { 11 | filter_t filter_gauss; 12 | 13 | filter_allocate(&filter_gauss, i); 14 | 15 | double sigma = 1 + (i - 3) / (double)(65 - 3) * 9; 16 | 17 | gauss_filter_generate(sigma, i, &filter_gauss); 18 | 19 | filter_normalize(&filter_gauss); 20 | 21 | snprintf(buffer, 255, "generated_filters/gauss_%d.txt", i); 22 | 23 | filter_save(buffer, &filter_gauss); 24 | 25 | filter_deallocate(&filter_gauss); 26 | } 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/gaussian_filter.c: -------------------------------------------------------------------------------- 1 | #define _USE_MATH_DEFINES 2 | 3 | #include "gaussian_filter.h" 4 | #include 5 | 6 | int gauss_filter_generate(double sigma, int size, filter_t* filter) { 7 | if (size % 2 == 0) 8 | return -1; 9 | 10 | if (filter->size != size) 11 | return -1; 12 | 13 | double r, s = 2.0 * sigma * sigma; 14 | 15 | int offset = size / 2; 16 | 17 | int index = 0; 18 | 19 | for (int y = -offset; y <= offset; y++) 20 | for (int x = -offset; x <= offset; x++) { 21 | r = sqrt(x * x + y * y); 22 | 23 | filter->array[index] = (exp(-(r * r) / s)) / (M_PI * s); 24 | 25 | index++; 26 | } 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/gaussian_filter.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_GAUSSIAN_FILTER_H 2 | #define SYSOPY_GAUSSIAN_FILTER_H 3 | 4 | #include "filter.h" 5 | 6 | int gauss_filter_generate(double sigma, int size, filter_t* filter); 7 | 8 | #endif // SYSOPY_GAUSSIAN_FILTER_H 9 | -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/generate_report.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | rm -f times.txt 3 | touch times.txt 4 | 5 | make filters_generator 6 | ./filters_generator 7 | 8 | make main 9 | 10 | for method in 0 1 11 | do 12 | if (( $method == 0 )) ; then 13 | printf "%s\n" " === BLOCK METHOD === " >> times.txt 14 | else 15 | printf "%s\n" " === INTERLEAVED METHOD === " >> times.txt 16 | fi 17 | 18 | for gauss_size in $(seq 3 8 65) 19 | do 20 | printf " --- Kernel size: $gauss_size --- \n" $ >> times.txt 21 | if (( $gauss_size <= 20 )) ; then 22 | THREAD_MAX_POWER=12 23 | else 24 | THREAD_MAX_POWER=3 25 | fi 26 | for thread_num_power in $(seq 0 $THREAD_MAX_POWER) 27 | do 28 | thread_num=$((2**$thread_num_power)) 29 | output=$(./main $thread_num $method images/lena.ascii.pgm \ 30 | $(printf "generated_filters/gauss_%d.txt" "$gauss_size") \ 31 | $(printf "images_out/output_%d.pgm" "$gauss_size") \ 32 | | tail -1) 33 | value=${output#*:} 34 | printf "Threads num: %4d Time: %s \n" $thread_num "$value" >> times.txt 35 | done 36 | done 37 | printf "\n\n" >> times.txt 38 | done -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/generated_filters/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/cw08/zad1_additional_things_done/generated_filters/.keep -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/image.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_IMAGE_H 2 | #define SYSOPY_IMAGE_H 3 | 4 | #define COLOR_BW (color_mode_t)1 5 | 6 | #define COLOR_GRAY (color_mode_t)2 7 | 8 | #define COLOR_RGB (color_mode_t)3 9 | 10 | typedef int color_mode_t; 11 | 12 | typedef struct img_t { 13 | int* array; 14 | int width; 15 | int height; 16 | int max_value; 17 | color_mode_t color_mode; 18 | } img_t; 19 | 20 | int img_allocate(img_t* image, 21 | int width, 22 | int height, 23 | int max_value, 24 | color_mode_t color_mode); 25 | 26 | int img_deallocate(img_t* image); 27 | 28 | int img_load(const char* path, img_t* out); 29 | 30 | int img_save(const char* path, img_t* image); 31 | 32 | int img_new(img_t* out, img_t* image); 33 | 34 | int img_getpixelindex(img_t* image, int x, int y, int* index); 35 | 36 | #endif // SYSOPY_IMAGE_H 37 | -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/images/script.sh: -------------------------------------------------------------------------------- 1 | #changes *.ppm binary to *.ppm ascii 2 | convert lena.ppm -compress none lena2.ppm 3 | 4 | -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/images_out/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/cw08/zad1_additional_things_done/images_out/.keep -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "filter.h" 5 | #include "gaussian_filter.h" 6 | #include "image.h" 7 | 8 | int main() { 9 | img_t image; 10 | img_load("images/lena.ascii.pgm", &image); 11 | 12 | img_t image_out; 13 | img_new(&image_out, &image); 14 | 15 | filter_t filter; 16 | 17 | filter_load("filters/emboss.txt", &filter); 18 | 19 | filter_normalize(&filter); 20 | 21 | for (int y = 0; y < image.height; y++) 22 | for (int x = 0; x < image.width; x++) 23 | filter_apply(&filter, &image, &image_out, x, y, EDGE_EXTEND); 24 | 25 | img_save("images_out/lena.ascii.pgm", &image_out); 26 | 27 | img_deallocate(&image); 28 | img_deallocate(&image_out); 29 | filter_deallocate(&filter); 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/utils.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int parse_int(const char* string, int* out) { 7 | errno = 0; 8 | char* end = NULL; 9 | 10 | int tmp = (int)strtol(string, &end, 10); 11 | if (errno != 0 || end == string) 12 | return -1; 13 | 14 | *out = tmp; 15 | 16 | return 0; 17 | } 18 | 19 | int parse_double(const char* string, double* out) { 20 | errno = 0; 21 | char* end = NULL; 22 | 23 | double tmp = strtod(string, &end); 24 | if (errno != 0 || end == string) 25 | return -1; 26 | 27 | *out = tmp; 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /cw08/zad1_additional_things_done/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSOPY_UTILS_H 2 | #define SYSOPY_UTILS_H 3 | 4 | int parse_int(const char* string, int* out); 5 | 6 | int parse_double(const char* string, double* out); 7 | 8 | #endif // SYSOPY_UTILS_H 9 | -------------------------------------------------------------------------------- /cw08/zad1_only_necessary_things_done/Makefile: -------------------------------------------------------------------------------- 1 | CC := gcc 2 | CFLAGS := -Wall -O3 -std=c99 -pthread 3 | HEADERS := error.h 4 | SRC := error.c filter.c 5 | OUT := filter 6 | RESULT := times.txt 7 | 8 | .PHONY: $(OUT) all test clean 9 | .DEFAULT: all 10 | 11 | all: $(OUT) 12 | 13 | $(OUT): $(SRC) $(HEADERS) 14 | $(CC) $(CFLAGS) $(SRC) -o $(OUT) 15 | 16 | test: $(OUT) 17 | ./$(OUT) 1 block mona.pgm edge.fil mona_edge.pgm > $(RESULT) 18 | ./$(OUT) 2 block mona.pgm edge.fil mona_edge.pgm >> $(RESULT) 19 | ./$(OUT) 4 block mona.pgm edge.fil mona_edge.pgm >> $(RESULT) 20 | ./$(OUT) 8 block mona.pgm edge.fil mona_edge.pgm >> $(RESULT) 21 | 22 | ./$(OUT) 1 interleaved mona.pgm edge.fil mona_edge.pgm >> $(RESULT) 23 | ./$(OUT) 2 interleaved mona.pgm edge.fil mona_edge.pgm >> $(RESULT) 24 | ./$(OUT) 4 interleaved mona.pgm edge.fil mona_edge.pgm >> $(RESULT) 25 | ./$(OUT) 8 interleaved mona.pgm edge.fil mona_edge.pgm >> $(RESULT) 26 | 27 | ./$(OUT) 1 block mona.pgm gauss.fil mona_gauss.pgm >> $(RESULT) 28 | ./$(OUT) 2 block mona.pgm gauss.fil mona_gauss.pgm >> $(RESULT) 29 | ./$(OUT) 4 block mona.pgm gauss.fil mona_gauss.pgm >> $(RESULT) 30 | ./$(OUT) 8 block mona.pgm gauss.fil mona_gauss.pgm >> $(RESULT) 31 | 32 | ./$(OUT) 1 interleaved mona.pgm gauss.fil mona_gauss.pgm >> $(RESULT) 33 | ./$(OUT) 2 interleaved mona.pgm gauss.fil mona_gauss.pgm >> $(RESULT) 34 | ./$(OUT) 4 interleaved mona.pgm gauss.fil mona_gauss.pgm >> $(RESULT) 35 | ./$(OUT) 8 interleaved mona.pgm gauss.fil mona_gauss.pgm >> $(RESULT) 36 | 37 | ./$(OUT) 1 block mona.pgm sharpen.fil mona_sharpen.pgm >> $(RESULT) 38 | ./$(OUT) 2 block mona.pgm sharpen.fil mona_sharpen.pgm >> $(RESULT) 39 | ./$(OUT) 4 block mona.pgm sharpen.fil mona_sharpen.pgm >> $(RESULT) 40 | ./$(OUT) 8 block mona.pgm sharpen.fil mona_sharpen.pgm >> $(RESULT) 41 | 42 | ./$(OUT) 1 interleaved mona.pgm sharpen.fil mona_sharpen.pgm >> $(RESULT) 43 | ./$(OUT) 2 interleaved mona.pgm sharpen.fil mona_sharpen.pgm >> $(RESULT) 44 | ./$(OUT) 4 interleaved mona.pgm sharpen.fil mona_sharpen.pgm >> $(RESULT) 45 | ./$(OUT) 8 interleaved mona.pgm sharpen.fil mona_sharpen.pgm >> $(RESULT) 46 | 47 | clean: 48 | $(RM) $(OUT) 49 | -------------------------------------------------------------------------------- /cw08/zad1_only_necessary_things_done/Readme.md: -------------------------------------------------------------------------------- 1 | ![image](https://user-images.githubusercontent.com/29823037/58035194-8dd58600-7b28-11e9-88a5-df73efadd45b.png) 2 | 3 | ![image](https://user-images.githubusercontent.com/29823037/58035240-a34ab000-7b28-11e9-8438-7e606fc5f976.png) 4 | -------------------------------------------------------------------------------- /cw08/zad1_only_necessary_things_done/edge.fil: -------------------------------------------------------------------------------- 1 | 3 2 | -1 -1 -1 3 | -1 8 -1 4 | -1 -1 -1 5 | -------------------------------------------------------------------------------- /cw08/zad1_only_necessary_things_done/error.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | void err(const char* format, ...) { 8 | va_list args; 9 | va_start(args, format); 10 | vfprintf(stderr, format, args); 11 | va_end(args); 12 | fputs("\n", stderr); 13 | exit(1); 14 | } 15 | 16 | void perr(const char* format, ...) { 17 | va_list args; 18 | va_start(args, format); 19 | vfprintf(stderr, format, args); 20 | va_end(args); 21 | fprintf(stderr, ": %s\n", strerror(errno)); 22 | exit(1); 23 | } 24 | -------------------------------------------------------------------------------- /cw08/zad1_only_necessary_things_done/error.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_ERROR_H 2 | #define LIST_ERROR_H 3 | 4 | void err(const char* format, ...); 5 | void perr(const char* format, ...); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /cw08/zad1_only_necessary_things_done/gauss.fil: -------------------------------------------------------------------------------- 1 | 9 2 | 0.0004849544 0.0013180469 0.0026921243 0.0041323173 0.0047667953 0.0041323173 0.0026921243 0.0013180469 0.0004849544 3 | 0.0013180469 0.0035822906 0.0073168651 0.0112311335 0.0129555673 0.0112311335 0.0073168651 0.0035822906 0.0013180469 4 | 0.0026921243 0.0073168651 0.0149447716 0.0229397048 0.0264618786 0.0229397048 0.0149447716 0.0073168651 0.0026921243 5 | 0.0041323173 0.0112311335 0.0229397048 0.0352116493 0.0406180636 0.0352116493 0.0229397048 0.0112311335 0.0041323173 6 | 0.0047667953 0.0129555673 0.0264618786 0.0406180636 0.0468545814 0.0406180636 0.0264618786 0.0129555673 0.0047667953 7 | 0.0041323173 0.0112311335 0.0229397048 0.0352116493 0.0406180636 0.0352116493 0.0229397048 0.0112311335 0.0041323173 8 | 0.0026921243 0.0073168651 0.0149447716 0.0229397048 0.0264618786 0.0229397048 0.0149447716 0.0073168651 0.0026921243 9 | 0.0013180469 0.0035822906 0.0073168651 0.0112311335 0.0129555673 0.0112311335 0.0073168651 0.0035822906 0.0013180469 10 | 0.0004849544 0.0013180469 0.0026921243 0.0041323173 0.0047667953 0.0041323173 0.0026921243 0.0013180469 0.0004849544 -------------------------------------------------------------------------------- /cw08/zad1_only_necessary_things_done/sharpen.fil: -------------------------------------------------------------------------------- 1 | 3 2 | 0 -1 0 3 | -1 5 -1 4 | 0 -1 0 5 | -------------------------------------------------------------------------------- /cw09/ancillary_materials/Mutual Exclusions, Condition Variables.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/cw09/ancillary_materials/Mutual Exclusions, Condition Variables.pdf -------------------------------------------------------------------------------- /cw09/zad1/Makefile: -------------------------------------------------------------------------------- 1 | CC := gcc 2 | CFLAGS := -Wall -O3 -std=c99 -pthread 3 | HEADERS := error.h 4 | SRC := error.c roller_coaster.c 5 | OUT := roller_coaster 6 | 7 | .PHONY: $(OUT) all test clean 8 | .DEFAULT: all 9 | 10 | all: $(OUT) 11 | 12 | $(OUT): $(SRC) $(HEADERS) 13 | $(CC) $(CFLAGS) $(SRC) -o $(OUT) 14 | 15 | test: $(OUT) 16 | ./$(OUT) 10 2 4 1 17 | 18 | clean: 19 | $(RM) $(OUT) -------------------------------------------------------------------------------- /cw09/zad1/error.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | void err(const char* format, ...) { 8 | va_list args; 9 | va_start(args, format); 10 | vfprintf(stderr, format, args); 11 | va_end(args); 12 | fputs("\n", stderr); 13 | exit(1); 14 | } 15 | 16 | void perr(const char* format, ...) { 17 | va_list args; 18 | va_start(args, format); 19 | vfprintf(stderr, format, args); 20 | va_end(args); 21 | fprintf(stderr, ": %s\n", strerror(errno)); 22 | exit(1); 23 | } 24 | -------------------------------------------------------------------------------- /cw09/zad1/error.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_ERROR_H 2 | #define LIST_ERROR_H 3 | 4 | void err(const char* format, ...); 5 | 6 | void perr(const char* format, ...); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /cw10/ancillary_materials/Sockets.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jakubowiczish/sysopy/aa6a268759252b5b5e9b08b3494d297489ec20e3/cw10/ancillary_materials/Sockets.pdf -------------------------------------------------------------------------------- /cw10/another_solution/zad1/Makefile: -------------------------------------------------------------------------------- 1 | CC := gcc 2 | CFLAGS := -Wall -O3 -std=c99 3 | HEADERS := error.h proto.h queue.h 4 | SRC := error.c proto.c 5 | 6 | .PHONY: $(OUT) all client server test clean 7 | .DEFAULT: all 8 | 9 | all: client server 10 | 11 | client: $(SRC) $(HEADERS) 12 | $(CC) $(CFLAGS) $(SRC) client.c -o client 13 | 14 | server: $(SRC) $(HEADERS) 15 | $(CC) $(CFLAGS) $(SRC) server.c -o server 16 | 17 | test: client server 18 | ./server 19 | 20 | clean: 21 | $(RM) client server 22 | -------------------------------------------------------------------------------- /cw10/another_solution/zad1/client.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "error.h" 13 | #include "proto.h" 14 | 15 | int main(int argc, char* argv[]) { 16 | if (argc != 4) { 17 | err("usage: %s name net_type address", argv[0]); 18 | } 19 | 20 | char* name = argv[1]; 21 | char* address = argv[3]; 22 | 23 | int unx = 0; 24 | if (strcmp(argv[2], "net") == 0) { 25 | unx = 0; 26 | } else if (strcmp(argv[2], "unix") == 0) { 27 | unx = 1; 28 | } else { 29 | err("invalid network type, use 'net' or 'unix'"); 30 | } 31 | 32 | int s; 33 | 34 | if (unx == 0) { 35 | s = socket(AF_INET, SOCK_STREAM, 0); 36 | if (s == -1) { 37 | perr("unable to create network socket"); 38 | } 39 | 40 | char ip[16]; 41 | int port = -1; 42 | 43 | sscanf(address, "%15[^:]:%d", ip, &port); 44 | 45 | printf("connecting to %s:%d\n", ip, port); 46 | 47 | struct sockaddr_in addr = {}; 48 | addr.sin_addr.s_addr = inet_addr(ip); 49 | addr.sin_family = AF_INET; 50 | addr.sin_port = htons(port); 51 | if (connect(s, (struct sockaddr*)&addr, sizeof(addr)) == -1) { 52 | perr("unable to connect to server"); 53 | } 54 | } else { 55 | s = socket(AF_UNIX, SOCK_STREAM, 0); 56 | if (s == -1) { 57 | perr("unable to create unix socket"); 58 | } 59 | 60 | printf("connecting to unix socket %s\n", address); 61 | 62 | struct sockaddr_un addr = {}; 63 | addr.sun_family = AF_UNIX; 64 | strcpy(addr.sun_path, address); 65 | if (connect(s, (struct sockaddr*)&addr, sizeof(addr)) == -1) { 66 | perr("unable to connect to server"); 67 | } 68 | } 69 | 70 | proto_send(s, name, strlen(name)); 71 | 72 | while (1) { 73 | char* data = proto_recv(s); 74 | 75 | int words = 0; 76 | 77 | char* text = data; 78 | while (*text) { 79 | if (isalpha(*text)) { 80 | words += 1; 81 | while (isalpha(*text)) 82 | ++text; 83 | } else { 84 | ++text; 85 | } 86 | } 87 | free(data); 88 | printf("words: %d\n", words); 89 | char buffer[16]; 90 | sprintf(buffer, "%d", words); 91 | 92 | sleep(5); 93 | proto_send(s, buffer, strlen(buffer)); 94 | } 95 | 96 | close(s); 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /cw10/another_solution/zad1/error.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | void err(const char* format, ...) { 8 | va_list args; 9 | va_start(args, format); 10 | vfprintf(stderr, format, args); 11 | va_end(args); 12 | fputs("\n", stderr); 13 | exit(1); 14 | } 15 | 16 | void perr(const char* format, ...) { 17 | va_list args; 18 | va_start(args, format); 19 | vfprintf(stderr, format, args); 20 | va_end(args); 21 | fprintf(stderr, ": %s\n", strerror(errno)); 22 | exit(1); 23 | } 24 | -------------------------------------------------------------------------------- /cw10/another_solution/zad1/error.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_ERROR_H 2 | #define LIST_ERROR_H 3 | 4 | void err(const char* format, ...); 5 | void perr(const char* format, ...); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /cw10/another_solution/zad1/proto.c: -------------------------------------------------------------------------------- 1 | #include "proto.h" 2 | #include 3 | #include 4 | #include 5 | #include "error.h" 6 | 7 | void proto_send(int fd, const char* buffer, int32_t size) { 8 | int32_t nsize = htonl(size); 9 | const char* data = (char*)&nsize; 10 | 11 | int32_t left = sizeof(nsize); 12 | int rc; 13 | 14 | do { 15 | if ((rc = write(fd, data, left)) < 0) { 16 | perr("unable to send length"); 17 | } 18 | 19 | data += rc; 20 | left -= rc; 21 | } while (left > 0); 22 | 23 | data = buffer; 24 | left = size; 25 | 26 | do { 27 | if ((rc = write(fd, data, left)) < 0) { 28 | perr("unable to send data"); 29 | } 30 | 31 | data += rc; 32 | left -= rc; 33 | } while (left > 0); 34 | } 35 | 36 | char* proto_recv(int fd) { 37 | int32_t size; 38 | char* data = (char*)&size; 39 | 40 | int32_t left = sizeof(size); 41 | int rc; 42 | 43 | do { 44 | if ((rc = read(fd, data, left)) < 0) { 45 | perr("unable to read length"); 46 | } 47 | 48 | if (rc == 0) { 49 | return NULL; 50 | } 51 | 52 | data += rc; 53 | left -= rc; 54 | } while (left > 0); 55 | 56 | size = ntohl(size); 57 | 58 | char* buffer = malloc(size + 1); 59 | data = buffer; 60 | left = size; 61 | 62 | do { 63 | if ((rc = read(fd, data, left)) < 0) { 64 | free(data); 65 | perr("unable to read data"); 66 | } 67 | 68 | if (rc == 0) { 69 | free(data); 70 | return NULL; 71 | } 72 | 73 | data += rc; 74 | left -= rc; 75 | } while (left > 0); 76 | 77 | *data = '\0'; 78 | return buffer; 79 | } 80 | -------------------------------------------------------------------------------- /cw10/another_solution/zad1/proto.h: -------------------------------------------------------------------------------- 1 | #ifndef PROTO_H 2 | #define PROTO_H 3 | 4 | #include 5 | 6 | void proto_send(int fd, const char* buffer, int32_t size); 7 | char* proto_recv(int fd); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /cw10/another_solution/zad1/queue.h: -------------------------------------------------------------------------------- 1 | #ifndef QUEUE_H 2 | #define QUEUE_H 3 | 4 | #include 5 | #include 6 | 7 | typedef struct queue_data_type { 8 | char* data; 9 | int32_t size; 10 | } queue_data_type; 11 | 12 | typedef struct queue_item { 13 | queue_data_type contents; 14 | struct queue_item* next; 15 | } queue_item; 16 | 17 | typedef struct queue_root { 18 | queue_item* head; 19 | queue_item* tail; 20 | } queue_root; 21 | 22 | void init_queue(queue_root* queue) { 23 | queue->head = queue->tail = NULL; 24 | } 25 | 26 | void push_queue(queue_root* queue, queue_data_type contents) { 27 | queue_item* item = malloc(sizeof(item)); 28 | item->contents = contents; 29 | item->next = NULL; 30 | if (queue->head == NULL) { 31 | queue->head = queue->tail = item; 32 | } else { 33 | queue->tail = queue->tail->next = item; 34 | } 35 | } 36 | 37 | queue_data_type pop_queue(queue_root* queue) { 38 | queue_data_type popped; 39 | if (queue->head == NULL) { 40 | return (queue_data_type){NULL, -1}; 41 | } else { 42 | popped = queue->head->contents; 43 | queue_item* next = queue->head->next; 44 | free(queue->head); 45 | queue->head = next; 46 | if (queue->head == NULL) 47 | queue->tail = NULL; 48 | } 49 | return popped; 50 | } 51 | 52 | #endif -------------------------------------------------------------------------------- /cw10/another_solution/zad2/Makefile: -------------------------------------------------------------------------------- 1 | D := ../zad1 2 | 3 | CC := gcc 4 | CFLAGS := -Wall -O3 -std=c99 -I$(D) 5 | HEADERS := $(D)/error.h proto.h 6 | SRC := $(D)/error.c proto.c 7 | 8 | .PHONY: $(OUT) all client server test clean 9 | .DEFAULT: all 10 | 11 | all: client server 12 | 13 | client: $(SRC) $(HEADERS) 14 | $(CC) $(CFLAGS) $(SRC) client.c -o client 15 | 16 | server: $(SRC) $(HEADERS) 17 | $(CC) $(CFLAGS) $(SRC) server.c -o server 18 | 19 | test: client server 20 | ./server 21 | 22 | clean: 23 | $(RM) client server 24 | -------------------------------------------------------------------------------- /cw10/another_solution/zad2/client.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "error.h" 13 | #include "proto.h" 14 | 15 | int main(int argc, char* argv[]) { 16 | if (argc != 4) { 17 | err("usage: %s name net_type address", argv[0]); 18 | } 19 | 20 | char* name = argv[1]; 21 | char* address = argv[3]; 22 | 23 | int unx = 0; 24 | if (strcmp(argv[2], "net") == 0) { 25 | unx = 0; 26 | } else if (strcmp(argv[2], "unix") == 0) { 27 | unx = 1; 28 | } else { 29 | err("invalid network type, use 'net' or 'unix'"); 30 | } 31 | 32 | int s; 33 | struct sockaddr_in addr_in = {}; 34 | struct sockaddr_un addr_un = {}; 35 | struct sockaddr* addr; 36 | 37 | if (unx == 0) { 38 | s = socket(AF_INET, SOCK_DGRAM, 0); 39 | if (s == -1) { 40 | perr("unable to create network socket"); 41 | } 42 | 43 | char ip[16]; 44 | int port = -1; 45 | 46 | sscanf(address, "%15[^:]:%d", ip, &port); 47 | 48 | printf("connecting to %s:%d\n", ip, port); 49 | 50 | addr_in.sin_addr.s_addr = inet_addr(ip); 51 | addr_in.sin_family = AF_INET; 52 | addr_in.sin_port = htons(port); 53 | addr = (struct sockaddr*)&addr_in; 54 | } else { 55 | s = socket(AF_UNIX, SOCK_DGRAM, 0); 56 | if (s == -1) { 57 | perr("unable to create unix socket"); 58 | } 59 | 60 | printf("connecting to unix socket %s\n", address); 61 | 62 | addr_un.sun_family = AF_UNIX; 63 | strcpy(addr_un.sun_path, address); 64 | addr = (struct sockaddr*)&addr_un; 65 | } 66 | proto_send_udp(s, addr, name, strlen(name)); 67 | while (1) { 68 | printf("awaiting text...\n"); 69 | char* data = proto_recv_udp(s, addr); 70 | 71 | int words = 0; 72 | 73 | char* text = data; 74 | while (*text) { 75 | if (isalpha(*text)) { 76 | words += 1; 77 | while (isalpha(*text)) 78 | ++text; 79 | } else { 80 | ++text; 81 | } 82 | } 83 | free(data); 84 | 85 | printf("words: %d\n", words); 86 | char buffer[16]; 87 | sprintf(buffer, "%d", words); 88 | 89 | sleep(5); 90 | proto_send_udp(s, addr, buffer, strlen(buffer)); 91 | } 92 | 93 | close(s); 94 | return 0; 95 | } 96 | -------------------------------------------------------------------------------- /cw10/another_solution/zad2/proto.h: -------------------------------------------------------------------------------- 1 | #ifndef PROTO_H 2 | #define PROTO_H 3 | 4 | #include 5 | #include 6 | 7 | void proto_send_udp(int fd, 8 | struct sockaddr* addr, 9 | const char* buffer, 10 | int32_t size); 11 | 12 | char* proto_recv_udp(int fd, struct sockaddr* addr); 13 | 14 | void proto_send(int fd, const char* buffer, int32_t size); 15 | char* proto_recv(int fd); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /cw10/complete_sollution/zad1/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | CFLAGS = -Wall 3 | HEADERS = 4 | SRC = 5 | 6 | .PHONY: clean 7 | 8 | all : main 9 | 10 | client : $(SRC) $(HEADERS) client.c queue.c errors.c utils.c colors.c 11 | $(CC) $(CFLAGS) $(SRC) client.c queue.c errors.c utils.c colors.c -D TCP -o client -pthread -lm 12 | 13 | server : $(SRC) $(HEADERS) server.c errors.c utils.c colors.c 14 | $(CC) $(CFLAGS) $(SRC) server.c errors.c utils.c colors.c -D TCP -o server -pthread -lm 15 | 16 | clean : 17 | rm -f client 18 | rm -f server 19 | 20 | -------------------------------------------------------------------------------- /cw10/complete_sollution/zad1/colors.c: -------------------------------------------------------------------------------- 1 | #include "colors.h" 2 | #include 3 | #include 4 | void set_color(char* color) { 5 | printf("%s", color); 6 | } 7 | void reset_color() { 8 | printf("%s\n", ANSI_COLOR_RESET); 9 | } 10 | void colorprintf(char* color, char* format, ...) { 11 | set_color(color); 12 | va_list args; 13 | va_start(args, format); 14 | vfprintf(stdout, format, args); 15 | va_end(args); 16 | reset_color(); 17 | } -------------------------------------------------------------------------------- /cw10/complete_sollution/zad1/colors.h: -------------------------------------------------------------------------------- 1 | #define ANSI_COLOR_RED "\x1b[31m" 2 | #define ANSI_COLOR_GREEN "\x1b[32m" 3 | #define ANSI_COLOR_YELLOW "\x1b[33m" 4 | #define ANSI_COLOR_BLUE "\x1b[34m" 5 | #define ANSI_COLOR_MAGENTA "\x1b[35m" 6 | #define ANSI_COLOR_CYAN "\x1b[36m" 7 | #define ANSI_COLOR_BRIGHT_RED "\x1b[91m" 8 | #define ANSI_COLOR_BRIGHT_GREEN "\x1b[92m" 9 | #define ANSI_COLOR_BRIGHT_YELLOW "\x1b[93m" 10 | #define ANSI_COLOR_BRIGHT_BLUE "\x1b[94m" 11 | #define ANSI_COLOR_BRIGHT_MAGENTA "\x1b[95m" 12 | #define ANSI_COLOR_BRIGHT_CYAN "\x1b[96m" 13 | #define ANSI_COLOR_RESET "\x1b[0m" 14 | 15 | void set_color(char* color); 16 | void reset_color(); 17 | void colorprintf(char* color, char* format, ...); -------------------------------------------------------------------------------- /cw10/complete_sollution/zad1/errors.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void pdie(char* message, int exit_code) { 5 | perror(message); 6 | exit(exit_code); 7 | } 8 | void die(char* message, int exit_code) { 9 | fprintf(stderr, "%s\n", message); 10 | exit(exit_code); 11 | } 12 | 13 | int perr(char* message, int return_code) { 14 | perror(message); 15 | return return_code; 16 | } 17 | int err(char* message, int return_code) { 18 | fprintf(stderr, "%s\n", message); 19 | return return_code; 20 | } 21 | 22 | void outperr(char* message) { 23 | perror(message); 24 | } 25 | 26 | void outerr(char* message) { 27 | fprintf(stderr, "%s\n", message); 28 | } -------------------------------------------------------------------------------- /cw10/complete_sollution/zad1/errors.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | void pdie(char* message, int exit_code); 3 | void die(char* message, int exit_code); 4 | 5 | int perr(char* message, int return_code); 6 | int err(char* message, int return_code); 7 | 8 | void outerr(char* message); 9 | void outperr(char* message); -------------------------------------------------------------------------------- /cw10/complete_sollution/zad1/queue.c: -------------------------------------------------------------------------------- 1 | #include "queue.h" 2 | #include 3 | int quenew(queue_t* queue) { 4 | queue->head = NULL; 5 | queue->tail = NULL; 6 | return 1; 7 | } 8 | 9 | int queclear(queue_t* queue) { 10 | node_t* node = queue->head; 11 | while (node != NULL) { 12 | node_t* tmp = node; 13 | node = node->next; 14 | free(tmp); 15 | } 16 | return 0; 17 | } 18 | 19 | int queadd(queue_t* queue, void* item) { 20 | node_t* node = malloc(sizeof(node_t)); 21 | node->value = item; 22 | node->next = NULL; 23 | 24 | if (queue->tail == NULL) { 25 | queue->tail = queue->head = node; 26 | } else { 27 | queue->tail->next = node; 28 | queue->tail = node; 29 | } 30 | 31 | return -1; 32 | } 33 | 34 | void* queget(queue_t* queue) { 35 | if (queue->head == NULL) 36 | return NULL; 37 | else { 38 | node_t* tmp = queue->head; 39 | queue->head = queue->head->next; 40 | if (queue->head == NULL) { 41 | queue->tail = NULL; 42 | } 43 | void* value = tmp->value; 44 | free(tmp); 45 | return value; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /cw10/complete_sollution/zad1/queue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | typedef struct node_t node_t; 6 | typedef struct node_t { 7 | node_t* next; 8 | void* value; 9 | } node_t; 10 | 11 | typedef struct queue_t { 12 | node_t* tail; 13 | node_t* head; 14 | } queue_t; 15 | 16 | int quenew(queue_t* queue); 17 | int queadd(queue_t* queue, void* item); 18 | void* queget(queue_t* queue); 19 | int queclear(queue_t* queue); -------------------------------------------------------------------------------- /cw10/complete_sollution/zad1/utils.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int parse_int(const char* string, int* out) { 7 | errno = 0; 8 | char* end = NULL; 9 | int tmp = (int)strtol(string, &end, 10); 10 | if (errno != 0 || end == string) 11 | return -1; 12 | *out = tmp; 13 | return 0; 14 | } 15 | 16 | int parse_double(const char* string, double* out) { 17 | errno = 0; 18 | char* end = NULL; 19 | double tmp = strtod(string, &end); 20 | if (errno != 0 || end == string) 21 | return -1; 22 | *out = tmp; 23 | return 0; 24 | } -------------------------------------------------------------------------------- /cw10/complete_sollution/zad1/utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | int parse_int(const char* string, int* out); 4 | int parse_double(const char* string, double* out); -------------------------------------------------------------------------------- /cw10/complete_sollution/zad2/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | CFLAGS = -Wall 3 | HEADERS = 4 | SRC = 5 | 6 | .PHONY: clean 7 | 8 | all : main 9 | 10 | client : $(SRC) $(HEADERS) ../zad1 ../../zad1 ../../zad1 ../../zad1 ../../zad1 11 | $(CC) $(CFLAGS) $(SRC) ../zad1/client.c ../zad1/queue.c ../zad1/errors.c ../zad1/utils.c ../zad1/colors.c -D UDP -o client -pthread -lm 12 | 13 | server : $(SRC) $(HEADERS) ../zad1 ../../zad1 ../../zad1 ../../zad1 14 | $(CC) $(CFLAGS) $(SRC) ../zad1/server.c ../zad1/errors.c ../zad1/utils.c ../zad1/colors.c -D UDP -o server -pthread -lm 15 | 16 | clean : 17 | rm -f client 18 | rm -f server 19 | 20 | -------------------------------------------------------------------------------- /format.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | echo "cleaning binaries..." 4 | find "$(git rev-parse --show-toplevel)" -name "zad*" -type d -exec make -C {} clean \; > /dev/null 5 | 6 | find "$(git rev-parse --show-toplevel)/lab" -mindepth 1 -maxdepth 1 -type d -exec make -C {} clean \; > /dev/null 7 | 8 | echo "formatting code..." 9 | find "$(git rev-parse --show-toplevel)" \( -name \*.h -o -name \*.cpp -o -name \*.c \) -type f -exec clang-format -i {} \; --------------------------------------------------------------------------------