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

@@ -19,12 +19,16 @@ void Webserv::run()
std::signal(SIGPIPE, signal_handler);
std::signal(SIGINT, signal_handler);
g_run = true;
family = PARENT;
g_family = PARENT;
while (g_run)
{
std::cout << family << "|" << ++count_loop << "-----loop epoll() ";
sem_wait(g_shmem); // protect output here
std::cout << g_family << "|" << ++count_loop << "-----loop epoll() ";
nfds = ::epoll_wait(_epfd, events, MAX_EVENTS, TIMEOUT);
std::cerr << "(nfds=" << nfds << ")" << std::endl;
sem_post(g_shmem); // protect output here
if (nfds == -1)
{
int errno_copy = errno;