Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save x-yuri/ac514fbc5da3a16cf3ec8c11b4f61b3a to your computer and use it in GitHub Desktop.
Save x-yuri/ac514fbc5da3a16cf3ec8c11b4f61b3a to your computer and use it in GitHub Desktop.
PID 1 processes doesn't have default signal handlers

PID 1 processes doesn't have default signal handlers

Dockerfile:

FROM alpine:3.20
COPY a.c .
RUN apk add build-base \
    && gcc a.c

a.c:

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

int main()
{
    setbuf(stdout, NULL);
    while (1) {
        putchar('.');
        sleep(1);
    }
    return EXIT_SUCCESS;
}
$ docker build -t i .
$ docker run --rm i ./a.out
...
$ docker exec `docker ps -q | head -1` apk add procps
$ docker exec `docker ps -q | head -1` ps -eHo pid,blocked,ignored,caught,args
    PID          BLOCKED          IGNORED           CAUGHT COMMAND
     15 0000000000000000 0000000000000000 000000007391fef9 ps -eHo pid,blocked,ignored,caught,args
      1 0000000000000000 0000000000000000 0000000000000000 ./a.out
$ docker exec `docker ps -q | head -1` kill 1
...
$ docker stop `docker ps -q | head -1`
(10 seconds delay)

a.rb:

while true
  print '.'
  sleep 1
end
$ docker run --rm -tv "$PWD:/host" ruby:3.3.4-alpine ruby host/a.rb
...
$ docker exec `docker ps -q | head -1` ps -eHo pid,blocked,ignored,caught,args
    PID          BLOCKED          IGNORED           CAUGHT COMMAND
     14 0000000000000000 0000000000000000 000000007391fef9 ps -eHo pid,blocked,ignored,caught,args
      1 0000000000000000 0000000000000000 0000000042017e4f ruby host/a.rb
$ echo $((`echo 'ibase=16; 42017E4F' | bc` & (1 << 14)))
16384
$ docker exec `docker ps -q | head -1` kill 1

https://github.com/ruby/ruby/blob/v3_3_4/signal.c#L1511

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment