This is a creation in Article, where the information may have evolved or changed.
Background
Today, before the release of a program, the QA feedback program ran 10 minutes after the QA test was put out
Troubleshooting Procedures
Adding a log to the program, the Discovery program captures a sigterm signal, and then does some cleanup before exiting (the data sent before exiting is still required). And then you need to know exactly which process sent me the sigterm signal.
Code
Look, it seems that the go language is not directly sent to get to their own signal to send the PID of the process, need to embed a C language code, get to the PID, in order to more intuitively know that the executable program, you can read/proc/${pid}/exe this soft chain
Packagemain/*#include <stdio.h>#include <signal.h>#include <string.h>#include <unistd.h>struct Sigaction old_action;void Handler (intSignum, siginfo_t*info, void*context) {printf("Sent by %d\ n", info->si_pid); Char path[1024x768]; Char res[1024x768]; memset (Path,' + ', sizeof (path)); memset (Res,' + ', sizeof (RES)); snprintf (path, sizeof (PATH),"/proc/%d/exe", info->si_pid);if(-1==Readlink(Path, res, sizeof (RES))) {printf("fail to get the symblic link of %s\ n", path); }Else{printf("The Symblic link of %s is: %s\ n", path, RES); }}void Test () {struct sigaction action; Sigaction (SIGTERM, NULL, &action); memset (&action,0, sizeof action); Sigfillset (&action.sa_mask); Action.sa_sigaction = handler; Action.sa_flags = Sa_nocldstop | Sa_siginfo | Sa_onstack; Sigaction (SIGTERM, &action, &old_action);}*/Import"C".... Func main () () {....... C.test () ...}