How can a program reboot my PC

本文介绍了如何通过程序实现计算机的冷启动和热启动,并提供了C语言代码示例。讨论了直接重启可能导致的数据丢失风险,以及如何通过模拟Ctrl-Alt-Del操作或发出磁盘重置指令来触发磁盘缓存刷新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 Subject: <Q:08.01> - How can a program reboot my PC?
Date: 8 Feb 2002 20:16:09 -0400

You can generate a "cold" boot or a "warm" boot. A cold boot is the same
as turning the power off and on; a warm boot is the same as Ctrl-Alt-Del
and skips the power-on self 'test.

For a warm boot, store the hex value 1234 in the word at 0040:0072. For
a cold boot, store 0 in that word. Then, if you want to live
dangerously, jump to address FFFF:0000. Here's C code to do it:

/* WARNING: data loss possible */
void bootme(int want_warm) /* arg 0 = cold boot, 1 = warm */
{
void (far* boot)(void) = (void (far*)(void))0xFFFF0000UL;

unsigned far* type = (unsigned far*)0x00400072UL;
*type = (want_warm ? 0x1234 : 0);
(*boot)( );
}

What's wrong with that method? It will boot right away, without closing
files, flushing disk caches, etc. If you boot without flushing a
write-behind disk cache (if one is running), you could lose data or
trash the file allocation table in your hard drive.

There are two methods of signaling the cache to flush its buffers:

(1) Simulate a keyboard Ctrl-Alt-Del in the keystroke translation
function of the BIOS (INT 15 AH=4F; but see notes below)

(2) Issue a disk reset (DOS function 0D). Most disk-cache programs hook
one or both of those interrupts, so if you use both methods you'll
probably be safe.

When user code simulates a Ctrl-Alt-Del, one or more of the programs
that have hooked INT 15 AH=4F can ask that the key be ignored by
clearing the carry flag. For example, HyperDisk does this when it has
started but not finished a cache flush. So if the carry flag comes back
cleared, the boot code has to wait a couple of clock ticks and then try
again. (None of this matters on older machines whose BIOS can't support
101- or 102-key keyboards; see the discussion of INT 21 AH=4F in
<Q:04.07> [What is the SysRq key for?])

C code that tries to signal the disk cache (if any) to flush is given
below. Turbo Pascal code by Timo Salmi that does more or less the same
job may be found at question 49 (as of this writing) in the Turbo Pascal
FAQ in comp.lang.pascal, and is downloadable as file FAQPAS2.TXT, which
is part of: <ftp://garbo.uwasa.fi/pc/link/>

Here's C code that reboots after trying to signal the disk cache:

#include <dos.h>

void bootme(int want_warm) /* arg 0 = cold boot, 1 = warm */
{
union REGS reg;

void (far* boot)(void) = (void (far*)(void))0xFFFF0000UL;
unsigned far* boottype = (unsigned far*)0x00400072UL;
char far* shiftstate = (char far*)0x00400017UL;
unsigned ticks;
int time_to_waste;

/* Simulate reception of Ctrl-Alt-Del: */
for (;;)
{
*shiftstate |= 0x0C; /* turn on Ctrl & Alt */
reg.h.ah = 0x4F; /* see notes below */
reg.h.al = 0x53; /* 0x53 = Del's scan code */
reg.x.cflag = 1; /* sentinel for ignoring key */
int86(0x15, &reg, &reg);

/* If carry flag is still set, we've finished. */
if(reg.x.cflag)
break;

/* Else waste some time before trying again: */
reg.h.ah = 0;
int86(0x1A, &reg, &reg); /* system time into CX:DX */

ticks = reg.x.dx;
for (time_to_waste = 3; time_to_waste > 0; )
{
reg.h.ah = 0;
int86(0x1A, &reg, &reg);
if (ticks != reg.x.dx)
ticks = reg.x.dx , --time_to_waste;
}
}

/* Issue a DOS disk reset request: */
reg.h.ah = 0x0D;
int86(0x21, &reg, &reg);

/* Set boot type and boot: */
*boottype = (want_warm ? 0x1234 : 0);
(*boot)( );
}

Reader Timo Salmi reported (26 July 1993) that the INT 15 AH=4F call may
not work on older PCs (below AT, XT2, XT286), according to Ralf Brown's
interrupt list (<Q:02.03> [What and where is Ralf Brown's interrupt
list?]).

Reader Roger Fulton reported (1 July 1993) that INT 15 AH=4F hangs even
a modern PC "ONLY when ANSI.SYS [is] loaded high using EMM386.EXE.
(Other things loaded high with EMM386.EXE were OK; ANSI.SYS loaded high
with QEMM386.SYS was OK; ANSI.SYS loaded low with EMM386.EXE installed
was OK.)" His solution was to use only the disk reset, INT 21 AH=0D,
which does flush SMARTDRV, then wait five seconds in hopes that any
other disk-caching software would have time to flush its queue.

Reader Per Bergland reported (10 Sep 1993) that the jump to FFFF:0000
will not work in Windows or other protected-mode programs. (For example,
when the above reboot code ran in a DOS session under Windows, a box
with "waiting for system shutdown" appeared. The PC hung and had to be
reset by cycling power.) His solution, which does a cold boot not a warm
boot, is to pulse pin 0 of the 8042 keyboard controller, which is
connected to the CPU's "reset" line.

He has tested the following code on various Compaqs, and expects it will
work for any AT-class machine; he cautions that you must first flush the
disk cache as indicated above.

cli
(AT) (AT) WaitOutReady: ; Busy-wait until 8042 ready for new command
in al,64h ; read 8042 status byte
test al,00000010b ; this bit indicates input buffer full
jnz (AT) (AT) WaitOutReady
mov al,0FEh ; Pulse "reset" = 8042 pin 0
out 64h,al ; The PC will reboot now
<think>好的,我现在需要帮助用户解决关于如何使用sys_reboot命令并附带参数a1b2c3d4的问题。首先,我需要确认用户提到的sys_reboot命令是否存在,因为在常见的Linux或Unix系统中,标准的系统重启命令通常是reboot、shutdown或init等,而sys_reboot可能是一个用户自定义的脚本或特定环境下的内部命令。 接下来,用户提到参考的引用内容是关于通过Docker进入数据库执行命令,这可能与当前问题无关,但需要留意是否有其他潜在联系。用户的需求是执行系统重启并附带特定参数a1b2c3d4,我需要考虑这个参数的作用。通常,系统重启命令的参数可能涉及时间设定、提示信息或强制操作等,但自定义参数可能需要特定的脚本处理。 可能的步骤如下:首先检查sys_reboot是否存在于系统环境变量中,可以通过which sys_reboot或command -v sys_reboot来验证。如果不存在,可能需要用户提供更多上下文,比如该命令的来源或文档。假设该命令存在且接受参数,正确的用法可能是sys_reboot a1b2c3d4,但需要权限,如使用sudo。 同时需要考虑权限问题,执行系统重启通常需要root权限,所以用户可能需要使用sudo。此外,参数a1b2c3d4可能对应某种配置或操作模式,需要用户确认其正确性,避免误操作导致系统问题。还需要提醒用户谨慎使用重启命令,确保数据已保存。 如果sys_reboot并非标准命令,可能需要建议用户查找相关文档或确认命令的正确性。最后,生成相关问题,帮助用户进一步理解系统命令的使用和权限管理。</think>根据您提供的信息,`sys_reboot`命令的用法需要结合系统权限和参数验证。以下是分步说明: 1. **权限验证** 系统级重启命令通常需要root权限: ```bash sudo sys_reboot a1b2c3d4 ``` 2. **参数有效性检查** - 若`a1b2c3d4`是预定义的安全令牌(常见于工业控制系统),需确认该参数已注册到系统配置中 - 若为自定义脚本参数,需检查脚本是否包含参数解析逻辑: ```bash # 示例脚本片段 if [ "$1" = "a1b2c3d4" ]; then /sbin/reboot fi ``` 3. **审计追踪建议** 重要操作建议添加日志记录: ```bash echo "$(date) - 触发重启参数a1b2c3d4" >> /var/log/sys_reboot.log ``` >[!WARNING] > 非标准系统命令的使用可能存在风险,请确认命令来源可靠性。生产环境中建议通过`systemctl`等标准命令管理
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值