diff --git a/lab2/src/part2_partitioner.cpp b/lab2/src/part2_partitioner.cpp index dd24925..61e5b87 100644 --- a/lab2/src/part2_partitioner.cpp +++ b/lab2/src/part2_partitioner.cpp @@ -84,10 +84,16 @@ int main(int argc, char **argv) cout << "[" << my_pid << "] forked right child " << children[1] << "\n"; } - waitpid(children[0], NULL, 0); - cout << "[" << my_pid << "] left child returned\n"; - waitpid(children[1], NULL, 0); - cout << "[" << my_pid << "] right child returned\n"; + for(int i = 0; i < 2; ++i) { + pid_t returned_pid = wait(NULL); + if(returned_pid == children[0]) { + cout << "[" << my_pid << "] left child returned\n"; + } + else { + cout << "[" << my_pid << "] right child returned\n"; + } + } + } else { @@ -96,8 +102,13 @@ int main(int argc, char **argv) { // Child process char start_str[10], end_str[10]; - sprintf(start_str, "%d", search_start_position); - sprintf(end_str, "%d", search_end_position); + + string temp = to_string(search_start_position); + strcpy(start_str, temp.c_str()); + + temp = to_string(search_end_position); + strcpy(end_str, temp.c_str()); + char *args[] = { "./part2_searcher.out", file_to_search_in, pattern_to_search_for, start_str, end_str ,NULL}; execv("./part2_searcher.out", args); } diff --git a/lab2/src/part3_partitioner.cpp b/lab2/src/part3_partitioner.cpp index 04e0dc4..8313e6f 100644 --- a/lab2/src/part3_partitioner.cpp +++ b/lab2/src/part3_partitioner.cpp @@ -113,10 +113,6 @@ int main(int argc, char **argv) } } - // waitpid(children[0], NULL, 0); - // cout << "[" << my_pid << "] left child returned\n"; - // waitpid(children[1], NULL, 0); - // cout << "[" << my_pid << "] right child returned\n"; } else { @@ -125,8 +121,13 @@ int main(int argc, char **argv) { // Child process char start_str[10], end_str[10]; - sprintf(start_str, "%d", search_start_position); - sprintf(end_str, "%d", search_end_position); + + string temp = to_string(search_start_position); + strcpy(start_str, temp.c_str()); + + temp = to_string(search_end_position); + strcpy(end_str, temp.c_str()); + char *args[] = { "./part3_searcher.out", file_to_search_in, pattern_to_search_for, start_str, end_str ,NULL}; execv("./part3_searcher.out", args); } diff --git a/lab2/src/part3_searcher.cpp b/lab2/src/part3_searcher.cpp index d5ccaf2..0575f5b 100644 --- a/lab2/src/part3_searcher.cpp +++ b/lab2/src/part3_searcher.cpp @@ -43,6 +43,7 @@ int main(int argc, char **argv) int len = sizeof(pattern_to_search_for); int search_start_position = atoi(argv[3]); int search_end_position = atoi(argv[4]); + int find = 0; pid_t pid = getpid(); ifstream file(file_to_search_in, ios::binary); @@ -51,6 +52,7 @@ int main(int argc, char **argv) buffer.resize(len2); file.seekg(search_start_position); file.read(&buffer[0], len2); + //TODO auto a = buffer.find(pattern_to_search_for); if(a != string::npos) {