Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Плохового ┐( ∵ )┌ #1

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9c31ca1
Плохового ┐( ∵ )┌
sergeyampo Feb 20, 2020
7fc994d
added hello.c and empty
Feb 20, 2020
f0c1ae8
Added swap function
Mar 5, 2020
47ca6e6
Revert string
Mar 5, 2020
1d83383
Added average script
Mar 5, 2020
445736b
Added static library
Mar 5, 2020
28a28ee
Shared library added
Mar 5, 2020
2ca4f8e
Ошибка в слове
sergeyampo Mar 5, 2020
5b5bd89
Compile shared library
Mar 20, 2020
980446a
Show how I've done it
Mar 20, 2020
1407b2c
Added CUnit tests
sergeyampo Mar 21, 2020
dde6ea9
Delete revert
sergeyampo Mar 21, 2020
f201dc7
Delete linkedrevert
sergeyampo Mar 21, 2020
e3b3d13
Delete librevert.a
sergeyampo Mar 21, 2020
3549035
Delete librevert_string.so
sergeyampo Mar 21, 2020
e56c468
Delete reverted
sergeyampo Mar 21, 2020
9d347ad
Delete tests
sergeyampo Mar 21, 2020
150e271
GetMinMax function
sergeyampo Apr 23, 2020
2ab0a74
Merge branch 'master' of https://github.com/sergeyampo/os_lab_2019
sergeyampo Apr 23, 2020
adc99e5
GetMinMax function support
sergeyampo Apr 23, 2020
6aabde4
Parallel minmax by fork and exec and makefiles
sergeyampo Apr 23, 2020
774b623
Added support killing child processes with time out
sergeyampo May 22, 2020
794877a
Zombie processes spawner
sergeyampo May 22, 2020
2d9538f
Added parallell_sum and threads amount comparison
sergeyampo May 23, 2020
118cbae
Process memory check
sergeyampo May 23, 2020
cc19c78
Correct bash script
sergeyampo May 23, 2020
cd37de3
Race condition example, using mutex to avoid this
sergeyampo Jun 1, 2020
c866b7f
factorial with mutex locking while multiplying main parts
sergeyampo Jun 2, 2020
2722ef2
Bash running
sergeyampo Jun 2, 2020
72c9d59
Deadlock example
sergeyampo Jun 2, 2020
98f069c
Partition intervals module added
sergeyampo Jun 17, 2020
fadf6a0
Multithreaded factorial(inefficiently for uint64_t sizes)
sergeyampo Jun 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
update.sh
/lab4/src/build/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Я написал программу: https://pastebin.com/YahFHx48. Я скомпилировал ее, и попытался ее выполнить, но получил ошибку "Invalid memory reference (SIGSEGV)".
Я загуглил ошибку, но так и не понял, как исправить.

### Пример плохового вопроса:
### Пример плохого вопроса:
Не работает: {тут код, который скопировали прямо в чат}.

### Время работы
Expand Down
Empty file added lab0/empty
Empty file.
6 changes: 6 additions & 0 deletions lab0/hello/newhello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdio.h>

int main()
{
printf("Hello World!\n");
}
17 changes: 17 additions & 0 deletions lab1/src/average.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

for (( a = 0; a < 150; a++ ))
do
echo $RANDOM
done > numbers.txt

let average=0
let cnt=0

while IFS= read -r number;
do
average=$((average + $number))
cnt=$((cnt + 1))
done < numbers.txt
echo $cnt
echo $((average / cnt))
12 changes: 7 additions & 5 deletions lab2/src/revert_string/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@

#include "revert_string.h"

int main(int argc, char *argv[])
int main(int argc, char* argv[])
{
if (argc != 2)
if (argc != 3)
{
printf("Usage: %s string_to_revert\n", argv[0]);
return -1;
}

char *reverted_str = malloc(sizeof(char) * (strlen(argv[1]) + 1));
strcpy(reverted_str, argv[1]);
unsigned arr_len = atoi(argv[1]);
char* reverted_str = malloc(sizeof(char) * (arr_len + 1));
strcpy(reverted_str, argv[2]);

RevertString(reverted_str);
RevertString(reverted_str, arr_len);

printf("Reverted: %s\n", reverted_str);
free(reverted_str);
return 0;
}


Binary file added lab2/src/revert_string/main.o
Binary file not shown.
Binary file added lab2/src/revert_string/revert.o
Binary file not shown.
11 changes: 7 additions & 4 deletions lab2/src/revert_string/revert_string.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "revert_string.h"

void RevertString(char *str)
{
// your code here
void RevertString(char* str, const unsigned arr_len) {
unsigned medium_index = arr_len / 2;
for (int i = 0; i < medium_index; ++i) {
char temp = str[i];
str[i] = str[arr_len - i - 1];
str[arr_len - i - 1] = temp;
}
}

2 changes: 1 addition & 1 deletion lab2/src/revert_string/revert_string.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

/* function to revert string */
void RevertString(char *str);
void RevertString(char *, const unsigned);

26 changes: 26 additions & 0 deletions lab2/src/revert_string/shared/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "revert_string.h"

int main(int argc, char* argv[])
{
if (argc != 3)
{
printf("Usage: %s string_to_revert\n", argv[0]);
return -1;
}

unsigned arr_len = atoi(argv[1]);
char* reverted_str = malloc(sizeof(char) * (arr_len + 1));
strcpy(reverted_str, argv[2]);

RevertString(reverted_str, arr_len);

printf("Reverted: %s\n", reverted_str);
free(reverted_str);
return 0;
}


Binary file added lab2/src/revert_string/shared/main.o
Binary file not shown.
6 changes: 6 additions & 0 deletions lab2/src/revert_string/shared/make_shared.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!
gcc -c -fPIC main.c -o main.o
gcc -c -fPIC revert_string.c -o revert_string.o
gcc -shared revert_string.o -o librevert_string.so
gcc main.o -L./ -lrevert_string -o reverted
LD_LIBRARY_PATH=$(pwd) ./reverted 9 123456789
5 changes: 5 additions & 0 deletions lab2/src/revert_string/shared/make_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!
#Start this script after make_shared
gcc -c tests.c -L./ -o tests.o
gcc tests.o -L./ -lrevert_string -lcunit -o tests
LD_LIBRARY_PATH=$(pwd) ./tests
10 changes: 10 additions & 0 deletions lab2/src/revert_string/shared/revert_string.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "revert_string.h"

void RevertString(char* str, const unsigned arr_len) {
unsigned medium_index = arr_len / 2;
for (int i = 0; i < medium_index; ++i) {
char temp = str[i];
str[i] = str[arr_len - i - 1];
str[arr_len - i - 1] = temp;
}
}
4 changes: 4 additions & 0 deletions lab2/src/revert_string/shared/revert_string.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

/* function to revert string */
void RevertString(char *, const unsigned);

Binary file added lab2/src/revert_string/shared/revert_string.o
Binary file not shown.
52 changes: 52 additions & 0 deletions lab2/src/revert_string/shared/tests.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <CUnit/Basic.h>
#include <stdio.h>
#include <string.h>

#include "revert_string.h"

void testRevertString(void) {
char simple_string[] = "Hello";
char str_with_spaces[] = "String with spaces";
char str_with_odd_chars_num[] = "abc";
char str_with_even_chars_num[] = "abcd";

RevertString(simple_string, 5);
CU_ASSERT_STRING_EQUAL_FATAL(simple_string, "olleH");

RevertString(str_with_spaces, 18);
CU_ASSERT_STRING_EQUAL_FATAL(str_with_spaces, "secaps htiw gnirtS");

RevertString(str_with_odd_chars_num, 3);
CU_ASSERT_STRING_EQUAL_FATAL(str_with_odd_chars_num, "cba");

RevertString(str_with_even_chars_num, 4);
CU_ASSERT_STRING_EQUAL_FATAL(str_with_even_chars_num, "dcba");
}

int main() {
CU_pSuite pSuite = NULL;

/* initialize the CUnit test registry */
if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error();

/* add a suite to the registry */
pSuite = CU_add_suite("Suite", NULL, NULL);
if (NULL == pSuite) {
CU_cleanup_registry();
return CU_get_error();
}

/* add the tests to the suite */
/* NOTE - ORDER IS IMPORTANT - MUST TEST fread() AFTER fprintf() */
if ((NULL == CU_add_test(pSuite, "test of RevertString function",
testRevertString))) {
CU_cleanup_registry();
return CU_get_error();
}

/* Run all tests using the CUnit Basic interface */
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
CU_cleanup_registry();
return CU_get_error();
}
Binary file added lab2/src/revert_string/shared/tests.o
Binary file not shown.
4 changes: 3 additions & 1 deletion lab2/src/swap/swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

void Swap(char *left, char *right)
{
// ваш код здесь
char temp = *left;
*left = *right;
*right = temp;
}
8 changes: 4 additions & 4 deletions lab2/src/tests/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ void testRevertString(void) {
char str_with_odd_chars_num[] = "abc";
char str_with_even_chars_num[] = "abcd";

RevertString(simple_string);
RevertString(simple_string, 5);
CU_ASSERT_STRING_EQUAL_FATAL(simple_string, "olleH");

RevertString(str_with_spaces);
RevertString(str_with_spaces, 18);
CU_ASSERT_STRING_EQUAL_FATAL(str_with_spaces, "secaps htiw gnirtS");

RevertString(str_with_odd_chars_num);
RevertString(str_with_odd_chars_num, 3);
CU_ASSERT_STRING_EQUAL_FATAL(str_with_odd_chars_num, "cba");

RevertString(str_with_even_chars_num);
RevertString(str_with_even_chars_num, 4);
CU_ASSERT_STRING_EQUAL_FATAL(str_with_even_chars_num, "dcba");
}

Expand Down
2 changes: 1 addition & 1 deletion lab2/text/lab2.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Необходимые знания

1. Как менять занчения переменных внутри функций в Си.
1. Как менять значения переменных внутри функций в Си.

### Задание
В папке swap лежит 3 файла: swap.c, swap.h и main.c. Ваша задача закончить метод Swap в swap.c, так, чтобы он менял местами два символа. Скомпилировать программу. Если вы все сделали верно, то программа, которую вы собрали выведет "b a".
Expand Down
Binary file added lab3/src/MietOSSequentially
Binary file not shown.
20 changes: 17 additions & 3 deletions lab3/src/find_min_max.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@

#include <limits.h>

struct MinMax GetMinMax(int *array, unsigned int begin, unsigned int end) {
struct MinMax GetMinMax(int* array, unsigned int begin, const unsigned int end) {
struct MinMax min_max;
min_max.min = INT_MAX;
min_max.max = INT_MIN;

// your code here
return min_max;
while(begin <= end)
{
/* If current element is greater than max */
if(array[begin] > min_max.max)
{
min_max.max = array[begin];
}

/* If current element is smaller than min */
if(array[begin] < min_max.min){
min_max.min = array[begin];
}
++begin;
}

return min_max;
}
2 changes: 1 addition & 1 deletion lab3/src/find_min_max.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

#include "utils.h"

struct MinMax GetMinMax(int *array, unsigned int begin, unsigned int end);
struct MinMax GetMinMax(int*, unsigned int, const unsigned int);

#endif
Binary file added lab3/src/first_task
Binary file not shown.
2 changes: 2 additions & 0 deletions lab3/src/first_task.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
gcc main.c find_min_max.c utils.c -o first_task
20 changes: 20 additions & 0 deletions lab3/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdio.h>
#include <stdlib.h>
#include "find_min_max.h"
#include "utils.h"

int main() {
const size_t size = 10;

int* array = (int*)malloc(sizeof(int) * size);
GenerateArray(array, size, 12);
struct MinMax min_max = GetMinMax(array, 0, size-1);

printf("Array is: ");
for(size_t i = 0; i < size; ++i){
printf("%d, ", array[i]);
}
printf("\nMinimum is: %d, maximum is: %d", min_max.min, min_max.max);

return 0;
}
Loading