I found a solution for my problem. I think this was a kubernetes-specific thing. After some research I found out that the worker-process get the status Zombie after sending the SIGTERM and the parent-process was not able to clean up the Zombie. So after adding tini as init-process (on dockerfile and deployment.yaml) and make sure it gets PID1 now the zombies are cleaned up and the worker-process is terminating when I send the SIGTERM from the admin-process.
I also tried to improve my signal-handler to make it safe again (thanks for your information in the comments). Now here the updated signal-handler and some parts of the rest of the program:
volatile atomic_int execute_loop = 1;
void handle_sigterm() {
error_msg(sip_man_log, "(MAIN) INFO: Signal reached.");
execute_loop = 0;
error_msg(sip_man_log, "(MAIN) INFO: Closing all sockets.");
close(sockfd_ext);
close(connfd);
close(sockfd);
}
int main()
{
struct sockaddr_in sockaddr, connaddr, sockaddr_ext;
unsigned int connaddr_len;
char buffer[8192];
int rv, rv_ext;
signal(SIGTERM, handle_sigterm);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
[...]
while(execute_loop)
{
connaddr_len = sizeof(connaddr);
connfd = accept(sockfd, (struct sockaddr*)&connaddr, &connaddr_len);
[...]
}
free_manipulation_table(int_modification_table);
free_manipulation_table(ext_modification_table);
free_manipulation_table(mir_modification_table);
error_msg(sip_man_log, "(MAIN) INFO: Terminating Server by SIGTERM");
return 0;
}
It's very shortened and I skipped most of the error-handling. Thanks for your help!
Dennis