added semaphore and shared memory to print without superposition between parent and child process

This commit is contained in:
hugogogo
2022-08-22 14:52:31 +02:00
parent 5225e3258b
commit f7b31c7db7
14 changed files with 127 additions and 65 deletions

View File

@@ -18,6 +18,10 @@
# include <unistd.h> // close, access
# include "colors.h" // for debug print_special
// debug
# include <sys/mman.h> // mmap (for shared memory)
# include <semaphore.h> // sem_init, sem_post, sem_wait
# define CR "\r"
# define LF "\n"
# define CRLF CR LF
@@ -63,6 +67,9 @@ struct listen_socket
bool operator==(const listen_socket& lhs, int fd);
bool operator==(int fd, const listen_socket& rhs);
extern family_state g_family;
extern sem_t* g_shmem;
std::vector<std::string> split(std::string input, char delimiter);
std::vector<std::string> split_trim(std::string input, std::string delim = "\n", char ctrim = '\0');
bool is_numeric(std::string str);
@@ -82,7 +89,10 @@ void str_map_key_tolower(std::map<std::string, std::string> & mp);
// debug
void throw_test();
void print_special(std::string str);
void* create_shared_memory(size_t size);
void init_semaphore();
void print_secure(int fd, std::string message);
void print_secure(std::string message);
/* Template */