[Bug 218266] Need article about Linux shutdown process

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



https://bugzilla.kernel.org/show_bug.cgi?id=218266

Rajesh (r.pandian@xxxxxxxxx) changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.pandian@xxxxxxxxx

--- Comment #4 from Rajesh (r.pandian@xxxxxxxxx) ---
Hello,

When graceful power,shutdown,reboot are done then the process are sent SIGTERM
and kernel gives them time to flush or finish their exit gracefully. Then it is
followed by SIGKILL which is a sure kill.

I made a test with the following C code. 

After compiling, I tested with poweroff, shutdown, reboot and even send a kill
PID and all of them logs with SIGNAL 15 which is the SIGTERM. 

As you can also notice, I have handled to flush the remaining bytes to the disk
and then close the file and followed by exit(0). 

Infact systemd does the same thing (Ref :
https://github.com/systemd/systemd/blob/main/src/shutdown/shutdown.c ) 

Note: This is a test code and it's log file can grow quiet large. So should not
be used in production.


/* Sample test code for handling SIGTERM for graceful shutdown, poweroff,
reboot or kill */

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

FILE *fp;

void signalHandler(int signal) {
  if ( signal == SIGTERM) {
     fprintf(fp, "Received signal is: %d\n", signal);
     fflush(fp);
     fclose(fp);
     exit(0);
  }
}

int main() {
  fp = fopen("a.log","w+");
  if (signal(SIGTERM,signalHandler) == SIG_ERR) 
     printf("\n SIGTERM CAUGHT");
  for (int i=0; ;i++) {
      fprintf(fp,"ok..\n");
      fflush(fp);
      sleep(2);
  }
}

-- 
You may reply to this email to add a comment.

You are receiving this mail because:
You are watching the assignee of the bug.




[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux