Upload files to "lab2/src"

This commit is contained in:
AAYUSH VATS VATS 2024-09-03 15:32:41 +05:30
parent feee8c3c8e
commit 349b546112
3 changed files with 26 additions and 12 deletions

View File

@ -84,10 +84,16 @@ int main(int argc, char **argv)
cout << "[" << my_pid << "] forked right child " << children[1] << "\n"; cout << "[" << my_pid << "] forked right child " << children[1] << "\n";
} }
waitpid(children[0], NULL, 0); for(int i = 0; i < 2; ++i) {
cout << "[" << my_pid << "] left child returned\n"; pid_t returned_pid = wait(NULL);
waitpid(children[1], NULL, 0); if(returned_pid == children[0]) {
cout << "[" << my_pid << "] right child returned\n"; cout << "[" << my_pid << "] left child returned\n";
}
else {
cout << "[" << my_pid << "] right child returned\n";
}
}
} }
else else
{ {
@ -96,8 +102,13 @@ int main(int argc, char **argv)
{ {
// Child process // Child process
char start_str[10], end_str[10]; 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}; char *args[] = { "./part2_searcher.out", file_to_search_in, pattern_to_search_for, start_str, end_str ,NULL};
execv("./part2_searcher.out", args); execv("./part2_searcher.out", args);
} }

View File

@ -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 else
{ {
@ -125,8 +121,13 @@ int main(int argc, char **argv)
{ {
// Child process // Child process
char start_str[10], end_str[10]; 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}; char *args[] = { "./part3_searcher.out", file_to_search_in, pattern_to_search_for, start_str, end_str ,NULL};
execv("./part3_searcher.out", args); execv("./part3_searcher.out", args);
} }

View File

@ -43,6 +43,7 @@ int main(int argc, char **argv)
int len = sizeof(pattern_to_search_for); int len = sizeof(pattern_to_search_for);
int search_start_position = atoi(argv[3]); int search_start_position = atoi(argv[3]);
int search_end_position = atoi(argv[4]); int search_end_position = atoi(argv[4]);
int find = 0; int find = 0;
pid_t pid = getpid(); pid_t pid = getpid();
ifstream file(file_to_search_in, ios::binary); ifstream file(file_to_search_in, ios::binary);
@ -51,6 +52,7 @@ int main(int argc, char **argv)
buffer.resize(len2); buffer.resize(len2);
file.seekg(search_start_position); file.seekg(search_start_position);
file.read(&buffer[0], len2); file.read(&buffer[0], len2);
//TODO //TODO
auto a = buffer.find(pattern_to_search_for); auto a = buffer.find(pattern_to_search_for);
if(a != string::npos) { if(a != string::npos) {