From 07d5d32cbd6c439e5d0351d6bb67d89d958f9f85 Mon Sep 17 00:00:00 2001 From: matv864 Date: Fri, 10 Jan 2025 16:59:44 +0000 Subject: [PATCH] make ready for linux --- task_3/counter_manager.cpp | 3 ++- task_3/counter_manager.h | 1 + task_3/log_writer.cpp | 16 +++++++--------- task_3/log_writer.h | 10 +++++----- task_3/main.cpp | 16 ++++++++-------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/task_3/counter_manager.cpp b/task_3/counter_manager.cpp index c8ff0f2..599e9ba 100644 --- a/task_3/counter_manager.cpp +++ b/task_3/counter_manager.cpp @@ -8,7 +8,8 @@ long long int CounterManager::get_counter() { int fd = open( "counter.txt", - _O_RDONLY + O_RDONLY, + 0777 ); if (fd == -1) { return 0; // Ошибка при открытии файла diff --git a/task_3/counter_manager.h b/task_3/counter_manager.h index 98833df..c8f228c 100644 --- a/task_3/counter_manager.h +++ b/task_3/counter_manager.h @@ -1,5 +1,6 @@ #include #include +#include class CounterManager { diff --git a/task_3/log_writer.cpp b/task_3/log_writer.cpp index f2295f0..962dd3e 100644 --- a/task_3/log_writer.cpp +++ b/task_3/log_writer.cpp @@ -4,7 +4,8 @@ int LogWriter::write_log(const std::string& log_line) { std::string new_line = "\n"; int fd = open( "main.log", - O_WRONLY|O_APPEND|O_CREAT + O_WRONLY|O_APPEND|O_CREAT, + 0777 ); if (fd == -1) { return -1; // Ошибка при открытии файла @@ -30,7 +31,7 @@ std::string LogWriter::get_current_time() { } -int LogWriter::log_start_line(){ +void LogWriter::log_start_line(){ std::string log_line = ( "start programm with pid " + std::to_string(getpid()) + @@ -38,11 +39,10 @@ int LogWriter::log_start_line(){ get_current_time() ); write_log(log_line); - return 0; } -int LogWriter::log_counter(long long int counter){ +void LogWriter::log_counter(long long int counter){ std::string log_line = ( "counter at " + get_current_time() + @@ -52,11 +52,10 @@ int LogWriter::log_counter(long long int counter){ std::to_string(counter) ); write_log(log_line); - return 0; } -int LogWriter::log_copy_start(std::string copy_name) { +void LogWriter::log_copy_start(std::string copy_name) { std::string log_line = ( copy_name + " is started at " + @@ -65,10 +64,9 @@ int LogWriter::log_copy_start(std::string copy_name) { std::to_string(getpid()) ); write_log(log_line); - return 0; } -int LogWriter::log_copy_finish(std::string copy_name) { +void LogWriter::log_copy_finish(std::string copy_name) { std::string log_line = ( copy_name + " is finished at " + @@ -77,7 +75,7 @@ int LogWriter::log_copy_finish(std::string copy_name) { write_log(log_line); } -int LogWriter::log_copy_error(std::string copy_name) { +void LogWriter::log_copy_error(std::string copy_name) { std::string log_line = ( copy_name + " is not finished" diff --git a/task_3/log_writer.h b/task_3/log_writer.h index 3df721c..4371cd9 100644 --- a/task_3/log_writer.h +++ b/task_3/log_writer.h @@ -6,11 +6,11 @@ class LogWriter { public: - static int log_start_line(); - static int log_counter(long long int counter); - static int log_copy_start(std::string copy_name); - static int log_copy_finish(std::string copy_name); - static int log_copy_error(std::string copy_name); + static void log_start_line(); + static void log_counter(long long int counter); + static void log_copy_start(std::string copy_name); + static void log_copy_finish(std::string copy_name); + static void log_copy_error(std::string copy_name); protected: static std::string get_current_time(); diff --git a/task_3/main.cpp b/task_3/main.cpp index c4a94ff..4d0a23a 100644 --- a/task_3/main.cpp +++ b/task_3/main.cpp @@ -22,8 +22,8 @@ struct two_pid { #else // Для UNIX-подобных систем struct two_pid launch_copies() { - std::string command1 = "main 1"; - std::string command2 = "main 2"; + std::string command1 = "./main 1"; + std::string command2 = "./main 2"; struct two_pid result; result.pid_1 = ProcessLauncher::launch(command1); result.pid_2 = ProcessLauncher::launch(command2); @@ -32,11 +32,11 @@ struct two_pid { #endif -uint64_t get_timestamp_ms() { +long long int get_timestamp_ms() { struct timeval tv; gettimeofday(&tv, NULL); - return (((long long)tv.tv_sec)*1000)+(tv.tv_usec/1000); + return (((long long int)tv.tv_sec)*1000)+(tv.tv_usec/1000); } @@ -63,10 +63,10 @@ int main(int argc, char* argv[]) { struct two_pid pid_of_copy_processes; - uint64_t last_counter_increment = get_timestamp_ms(); - uint64_t last_counter_logging = get_timestamp_ms(); - uint64_t last_copies_launching = get_timestamp_ms(); - uint64_t current_time; + long long int last_counter_increment = get_timestamp_ms(); + long long int last_counter_logging = get_timestamp_ms(); + long long int last_copies_launching = get_timestamp_ms(); + long long int current_time; while (1) { current_time = get_timestamp_ms();