From: bugzilla-daemon@kernel.org
To: linux-man@vger.kernel.org
Subject: [Bug 218266] Need article about Linux shutdown process
Date: Fri, 22 Dec 2023 14:09:17 +0000 [thread overview]
Message-ID: <bug-218266-11311-qRTq2nvtHy@https.bugzilla.kernel.org/> (raw)
In-Reply-To: <bug-218266-11311@https.bugzilla.kernel.org/>
https://bugzilla.kernel.org/show_bug.cgi?id=218266
Rajesh (r.pandian@gmail.com) changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |r.pandian@gmail.com
--- Comment #4 from Rajesh (r.pandian@gmail.com) ---
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.
next prev parent reply other threads:[~2023-12-22 14:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-15 6:29 [Bug 218266] New: Need article about Linux shutdown process bugzilla-daemon
2023-12-15 10:27 ` [Bug 218266] " bugzilla-daemon
2023-12-15 11:24 ` bugzilla-daemon
2023-12-15 11:34 ` bugzilla-daemon
2023-12-22 14:09 ` bugzilla-daemon [this message]
2023-12-22 19:14 ` bugzilla-daemon
2023-12-25 10:19 ` bugzilla-daemon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-218266-11311-qRTq2nvtHy@https.bugzilla.kernel.org/ \
--to=bugzilla-daemon@kernel.org \
--cc=linux-man@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox