TransWikia.com

How to prove "reboot -f" command is blocking?

Unix & Linux Asked by ArcherIndigo on November 16, 2021

While writing shell script for an embedded Linux device, my colleges tends to add a infinite loop after reboot / reboot -f command to make sure the later part of the script won’t run during reboot. However I wonder whether reboot -f is actually a blocking command or not.

I tried reboot; touch test and test is created. Thus a normal reboot should be non-blocking. However, running reboot -f ; touch test command won’t create test. Some may argue that touch or the shell might have been killed before touch` can execute so it is not a sufficient proof.

The reboot is actually sym-link to sysvinit’s halt executable.

May someone gives a proof or an explanation? Thanks.

One Answer

Depending on your OS, reboot can be very different. For me, reboot is a symlink to systemctl:

ls -la /sbin/reboot
lrwxrwxrwx 1 root root 14 maj  3 13:30 /sbin/reboot -> /bin/systemctl

In this case, it is equivalent to systemctl reboot which is equivalent to systemctl start reboot.target --job-mode=replace-irreversibly --no-block (see manpage of systemctl).

-force will in this case just speed up the process of rebooting, probably resulting in the shell being killed before the file was touched.
If you want this to be blocking, you could try something like systemctl start reboot.target --job-mode=replace-irreversibly. But I'm not sure if a blocking reboot can be achieved like this.

If you are on a non-systemd environment, reboot might work differently for you, though.

I think, an infinite loop is not the cleanest solution here, you could just do exit after the reboot.

Answered by toydarian on November 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP