首页 > 编程知识 正文

操作系统 startxxinit,马扎克系统编程操作手册

时间:2023-05-06 15:10:45 阅读:225259 作者:1951

了解startx/xinit

1.概述

  用户可以通过 xinit 程序手动启动 Xorg 显示服务器,startx脚本是 xinit 的前端。

  xinit 通常用在启动 X 时执行窗口管理器 或 桌面环境。虽然可以使用 xinit 在无窗口管理器的情况下启动图形程序,大部分图形程序都需要一个兼容 EWMH 的窗口管理器。显示管理器 启动 Xorg 并读取 xprofile。

  启动X主要有两种方法:

一是Display Manager,如XDM、GDM、KDM,此种方法通过图形界面登录;另一种是通过xinit,此种方法适用于字符界面登录。

  常用于登录X的startx命令也是通过传递参数给xinit来启动X的,也就是说,最终启动X的是xinit。startx只是一个bash脚本。

1.1.startx

  The startx script is a front end to xinit that provides a somewhat nicer user interface for running a single session of the X Window System. It is often run with no arguments.

  startx命令用来启动X-Window,它负责调用X-Window系统的初始化程序xinit。以完成 X-Window运行所必要的初始化工作,并启动X-Window系统。

  startx 最重要的任务就是找出使用者或者是系统默认的 X server 与 X client 的配置档,而使用者也能够使用 startx 外接参数来取代配置档的内容。这个意思是说:startx 可以直接启动,也能够外接参数,例如底下格式的启动方式:

[root@www ~]# startx [X client 参数] – [X server 参数]

参考实例:已默认方式启动X-windows系统:[root@linuxcool ~]# startx以16位颜色深度启动X-windows系统:[root@linuxcool ~]# startx -- -depth 16强制启动 X-windows系统:[root@linuxcool ~]# startx -w要使用 .xinitrc 脚本启动 X 会话,请输入:startx -x .xinitrc要使用 mwm 窗口管理器启动 X 会话,请输入:startx -m mwm

1.2.xinit

  当 startx 找到需要的配置值后,就呼叫 xinit 实际启动 X 。xinit先启动先启动X服务器,再启动基于X的应用程序。事实上启动 X 的是 xinit 这支程序, startx 仅是在帮忙找出配置值而已!那么 startx 找到的配置值可用顺序为何呢?基本上是这样的:

X server 的参数方面:
使用 startx 后面接的参数;
若无参数,则找寻使用者家目录的文件,亦即 ~/.xserverrc
若无上述两者,则以 /etc/X11/xinit/xserverrc
若无上述三者,则单纯运行 /usr/羞涩的花卷/X (此即 X server 运行档)

X client 的参数方面:
使用 startx 后面接的参数;
若无参数,则找寻使用者家目录的文件,亦即 ~/.xinitrc
若无上述两者,则以 /etc/X11/xinit/xinitrc
若无上述三者,则单纯运行 xterm (此为 X 底下的终端机软件)

1.2.1.启动 X server 的文件: xserverrc

  xserverrc 文件是一个启动 X server 的 shell 脚本。如果存在 ~/.xserverrc ,startx 和 xinit 都会执行这个文件。如果文件不存在,startx 会使用 /etc/X11/xinit/xserverrc.

1 #!/羞涩的花卷/sh 2 3 exec /usr/羞涩的花卷/X -nolisten tcp "$@"

  X 窗口最先需要启动的就是 X server,那 X server 启动的脚本与参数是透过 /etc/X11/xinit/ 里面的 xserverrc 。其实就是运行 /usr/羞涩的花卷/X 这个命令啊! 这个命令也是系统最原始的 X server。

  在启动 X Server 时,Xorg 会去读取 /etc/X11/xorg.conf 这个配置档。如果一切顺利,那么 X 就会顺利的在 tty7 的环境中启动了 X 。 单纯的 X 启动时,你只会看到画面一片漆黑,然后中心有个鼠标的光标而已。

  启动了 X server 后,接下来就是加载 X client 到这个 X server 上面啦!

1.2.2.xinitrc

  假设家目录并没有 ~/.xinitrc ,则此时 X Client 会以 /etc/X11/xinit/xinitrc 来作为启动 X Client 的默认脚本。最后,其实最终就是加载 KDE 或者是 GNOME 而已。

  ~/.xinitrc 可以方便的启动依赖 X 的程序,并在 X 启动时设置环境变量。如果用户主目录中存在 .xinitrc,startx 和 xinit 会执行此文件。如果不存在,startx 会执行默认的 /etc/X11/xinit/xinitrc。

/etc/X11/xinit/xinitrc: 7 # invoke global X session script 8 . /etc/X11/Xsession

1.2.3.Xsession

  A display manager refers to a user’s login and startup of a window manager and desktop as a session. When the user quits the desktop and logs out, the session ends. When another user logs in, a new session starts. The X Window System never shuts down; only desktop or window manager programs shut down. Session menus on the display manager login window list different kinds of sessions you can start—in other words, different kinds of window managers or desktops. For each session, the Xsession script is the startup script used to configure a user’s X Window System display and to execute the selected desktop or window manager. Although this script is unnecessary for gdm, it is still used in the gdm Red Hat implementation.

  Xsession is the display manager session startup script used by the Red Hat implementation of gdm (other display managers such as kdm and xdm also use Xsession). It contains many of the X commands also used with the xinitrc startup script. Xsession usually executes the same xmodmap and xrdb commands using the .Xmodmap and .Xrsources files in the /etc/X11/xinit directory. Shown here is the Xsession script used by gdm on Red Hat systems, which is located in the /etc/X11/xdm directory. Notice that any errors are saved in the user’s .xsession-errors file in their home directory. Xsession will also read any shell scripts located in the /etc/X11/xinit/xinitrc.d directory. Currently this holds an input script to detect the kind of language a keyboard uses.

/etc/X11/Xsession.d/00deepin-dde-env: 1 if [ "$1" = "/usr/羞涩的花卷/startdde" ]; then 2 if [ -f "$HOME/.dde_env" ]; then 3 . "$HOME/.dde_env" 4 # Handling configuration migration issues 5 if [ -n "$QT_SCALE_FACTOR" ]; then 6 unset QT_SCALE_FACTOR 7 unset QT_SCREEN_SCALE_FACTORS 8 unset QT_AUTO_SCREEN_SCALE_FACTOR 9 unset QT_FONT_DPI 10 export STARTDDE_MIGRATE_SCALE_FACTOR=1 11 fi 12 elif [ -f "$HOME/.pam_environment" -a -n "$QT_SCALE_FACTOR" ]; then 13 # Handling configuration migration issues for earlier version 14 unset QT_SCALE_FACTOR 15 export STARTDDE_MIGRATE_SCALE_FACTOR=1 16 fi 17 fi

小结:startx 的默认启动过程为: startx 调用并将系统文件 /etc/X11/xinit/xinitrc 和 /etc/X11/xinit/xserverrc 作为参数传给 xinit , xinit 就会先执行系统文件 /etc/X11/xinit/xserverrc 以启动 X Server ,然后执行 /etc/X11/xinit/xinitrc ,而 xinitrc 则会执行脚本 /etc/X11/Xsession ,而 Xsession 则会按顺序调用执行 /etc/X11/Xsession.d 目录下的文件,从而最终调用了 gnome-session 这个用于 启动 GNOME 桌面环境的程序

refer to

https://www.computerhope.com/unix/startx.htmhttp://cn.linux.vbird.org/linux_basic/0590xwindow.phphttps://wiki.archlinux.org/index.php/Xinit_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。