make ready for linux
This commit is contained in:
parent
3ef5493892
commit
07d5d32cbd
@ -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; // Ошибка при открытии файла
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <string>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
class CounterManager {
|
||||
|
@ -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"
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user