[LINUX] I wrote you to watch the signal with Go

tl;dt https://github.com/nozo-moto/signal_kansitai


A little research, I wanted to know what kind of signal was sent to the application


Go language can handle when there is a signal in the created goroutine by doing the following.

c := make(chan os.Signal)
go func() {
	for {
		s := <-c
		log.Println("signal :", s)

Good logging I wanted to write to standard output and log file, so I used ʻio.MultiWriter`

logfile, err := os.OpenFile("./signal.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
	panic("cannnot create log :" + err.Error())
defer logfile.Close()
log.SetOutput(io.MultiWriter(logfile, os.Stdout))
log.SetFlags(log.Ldate | log.Ltime)

It handles the signal like this and sends it

% tail -f signal.log
2020/02/09 21:48:01 alive :
2020/02/09 21:49:01 alive :
2020/02/09 21:50:01 alive :
2020/02/09 21:50:33 signal : hangup false

I tried to drop it when SIGTERM was sent. Survival is confirmed once every 60 seconds. Also, systems that cannot be handled, such as SIGKILL, cannot be handled and die.


I found out that there is a signal to change the window size of the terminal called SIGWINCH.

Recommended Posts

I wrote you to watch the signal with Go
I tried to analyze the whole novel "Weathering with You" ☔️
I wrote it in Go to understand the SOLID principle
I wrote a script to get you started with AtCoder fast!
I tried to save the data with discord
I wanted to play with the Bezier curve
I wrote the hexagonal architecture in go language
I made you to express the end of the IP address with L Chika
I wrote a script to revive the gulp watch that will die soon
I tried to learn the sin function with chainer
I tried to touch the CSV file with Python
I tried to solve the soma cube with python
I want to inherit to the back with python dataclass
I tried to solve the problem with Python Vol.1
I wrote a CLI tool in Go language to view Qiita's tag feed with CLI
How to test the current time with Go (I made a very thin library)
I wrote GP with numpy
Connect to Postgresql with GO
I tried to find the entropy of the image with python
I tried to simulate how the infection spreads with Python
I wrote the code for Japanese sentence generation with DeZero
I wanted to solve the Panasonic Programming Contest 2020 with Python
read the tag assigned to you on ec2 with boto3
I tried to notify the train delay information with LINE Notify
I wrote a program quickly to study DI with Python ①
Move what you installed with pip to the conda environment
What I did to welcome the Python2 EOL with confidence
[Python] I want to use the -h option with argparse
I can't log in to the admin page with Django3
I wrote a script to combine the divided ts files
I captured the Touhou Project with Deep Learning ... I wanted to.
I tried to divide the file into folders with Python
I wrote the basic operation of matplotlib with Jupyter Lab
I wrote a doctest in "I tried to simulate the probability of a bingo game with Python"
I tried to describe the traffic in real time with WebSocket
I tried to solve the ant book beginner's edition with python
I want to know the weather with LINE bot feat.Heroku + Python
I tried to automate the watering of the planter with Raspberry Pi
Nice to meet you with python
I made a web server with Raspberry Pi to watch anime
[Introduction to StyleGAN] I played with "The Life of a Man" ♬
I want to output the beginning of the next month with Python
I tried to process the image in "sketch style" with OpenCV
I wrote the code to write the code of Brainf * ck in python
I calculated the stochastic integral (I to integral)
[Introduction to sinGAN-Tensorflow] I played with the super-resolution "Challenge Big Imayuyu" ♬
I tried to get started with Bitcoin Systre on the weekend
I liked the tweet with python. ..
I wrote the basic operation of Pandas with Jupyter Lab (Part 1)
I wanted to solve the ABC164 A ~ D problem with Python
I tried to process the image in "pencil style" with OpenCV
I wrote the queue in Python
For the time being, I want to convert files with ffmpeg !!
I want to do ○○ with Pandas
I want to check the position of my face with OpenCV!
What to do when you get "I can't see the site !!!!"
I tried to improve the efficiency of daily work with Python
I want to debug with Python
I compared while reading the documentation to use Jinja2 with Django
I wrote the basic operation of Pandas with Jupyter Lab (Part 2)
I tried to move the ball