Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
You can kill a process by kill command. But have you thought what would happen to the process which is runing if you issue kill command? It will do something nasty in between if you do not handle the kill signal gracefully. If you are writing to a file, it will
corrupt the file, if you are sending RPC messages, you will break the process in between and drop all messages.

To handle signal you can use signal python module. A sample of the signal handling is created as a gist in github below:

- https://gist.github.com/alirezastack/ae4e12a21ccb91264b69e1d14a53c044

The above method will handle SIGINT, SIGTERM and end the loop gracefully.

To test it you can run the script in terminal and then try to find the pid number of the process and finally kill it:

sudo kill 4773

The above command will issue SIGTERM and script will handle it gracefully. SIGINT on the other hand is issued when you press CTRL+C.

#python #sigint #sigterm #signal #kill
Hello Docker geeks :)

If you run a container and attach to that container you would see its stin, stout or stderr outputs. If you press CTRL+C while you're attached to the container the container will get stopped. In order to detach from the container you can use key sequence CTRL+ p + CTRL+q.

One of the reasons that CTRL+C stops the container is that this key combination sends SIGKILL signal to the container. There is a
parameter called --sig-proxy that is true by default which makes CTRL+C to send SIGINT. You can detach from a container and leave it running using the CTRL-p CTRL-q key sequence.

If you set --sig-proxy to false then CTRL+C would not kill the running container:

docker attach YOUR_CONTAINER_ID --sig-proxy=false

NOTE: you can get container id by issuing docker ps command.

#docker #attach #detach #sig_proxy #sequence_key #SIGINT #SIGKILL