在计算机启动时,BIOS(基本输入输出系统)会进行自检,然后根据启动顺序从指定设备(通常是硬盘)加载引导加载器(如GRUB)。引导加载器负责加载Linux内核到内存中。
内核加载完成后,它会启动第一个用户空间进程,即init
进程,其PID(进程ID)为1。在较旧的系统中,init
的类型可能是SysV、Upstart或Systemd。
/etc/inittab
配置文件。/etc/inittab
和/etc/init/*.conf
配置文件。/usr/lib/systemd/system
和/etc/systemd/system
配置文件。init
进程根据配置文件和运行级别来启动系统服务和守护进程。
系统初始化完成后,会建立终端,允许用户登录。
用户在终端输入用户名和密码,通过认证后登录系统。
Linux系统有7个运行级别,每个级别对应不同的系统状态和启动的服务集合。
以下是一个简单的Systemd服务配置文件示例,用于在系统启动时自动启动一个简单的Python脚本。
hello.py
:python#!/usr/bin/env python3
import datetime
print("Hello, world! The time is:", datetime.datetime.now())
bashchmod +x /path/to/hello.py
hello.service
:ini[Unit]
Description=Hello World Service
[Service]
ExecStart=/path/to/hello.py
Type=simple
[Install]
WantedBy=multi-user.target
bashsudo cp hello.service /etc/systemd/system/
bashsudo systemctl enable hello.service
bashsudo systemctl start hello.service
这个示例展示了如何创建一个简单的Python脚本,并将其配置为Systemd服务,以便在系统启动时自动运行。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。