彻底理解Linux的DISPLAY变量的作用

背景

最近遇到个两年前遇到的问题,使用virt-manager提示(virt-manager:873): Gtk-WARNING **: 14:53:28.147: cannot open display: :1,当时专门运维的同事帮忙临时调了下DISPLAY变量,好像是将:1改成了SSH用户本地IP:10.0,当时的确好了,用完就关了再没用到,也没深究原因,那个运维同事也不大理解(网上查到的解决办法)。然而最近在做资产盘点,领导让我把我挂名管理的服务器作置换申请,需要知道虚拟机的信息,赶上盘到两年前有问题的机器上,又出现同样的问题,经过查找了资料找到了个几乎万无一失的理解,记一记。

DISPLAY变量是啥

首先,它是Linux X11 server(显示服务)用到的一个环境变量,用来指示你的显示(也可以包含键盘和鼠标)指向的显示服务地址,通常桌面PC该值会被设为:0.0

其次,它的格式有三部分: [主机名]:显示服务端口号-6000.显示器编号

  • [主机名] :一般是可以省略的,可以不写,也可以写成$HOSTNAME变量表示的主机名 或 localhost
  • 显示服务端口号-6000:意思是sshd服务的X11Forwarding占用端口减去6000的值
  • 显示器编号:一般都是0,表示第一个显示器

如何正确设置DISPLAY变量

分两种情况:

  • Linux桌面系统:直接设置:0.0
  • SSH连接的Linux服务器:需要按照格式进行检查。

检查步骤如下:

[root@hz ~]# netstat -anpt |grep sshd |grep LISTEN |grep 60
tcp   0  0 127.0.0.1:6010  0.0.0.0:*  LISTEN   30346/sshd: root@pt
tcp6  0  0 ::1:6010        :::*       LISTEN   30346/sshd: root@pt

找到60开头的sshd端口,这时是6010,减去6000是10,SSH只写第一显示器编号

则我的DISPLAY变量可设为 :10.0 或者 hz:10.0

如果上边的命令查不出来6000左右的端口号,请检查 /etc/ssh/sshd_config,确认X11Forwarding yes参数已配置并systemctl restart sshd,使用exit退出当前ssh,重新连接再尝试。

附:参考

The magic word in the X window system is DISPLAY. A display consists (simplified) of:

  • a keyboard,
  • a mouse
  • and a screen.

A display is managed by a server program, known as an X server. The server serves displaying capabilities to other programs that connect to it.

The remote server knows where it has to redirect the X network traffic via the definition of the DISPLAY environment variable which generally points to an X Display server located on your local computer.

The value of the display environment variable is:

hostname:D.S

where:

hostname is the name of the computer where the X server runs. An omitted hostname means the localhost.

D is a sequence number (usually 0). It can be varied if there are multiple displays connected to one computer.

S is the screen number. A display can actually have multiple screens. Usually, there’s only one screen though where 0 is the default.

Example of values

localhost:4
google.com:0
:0.0

hostname:D.S means screen S on display D of host hostname; the X server for this display is listening at TCP port 6000+D.

host/unix:D.S means screen S on display D of host host; the X server for this display is listening at UNIX domain socket /tmp/.X11-unix/XD (so it’s only reachable from host).

:D.S is equivalent to host/unix:D.S, where host is the local hostname.

:0.0 means that we are talking about the first screen attached to your first display in your local host

Read more here: support.objectplanet.com and here: superuser.com and here: docstore.mik.ua.

From a X(7) man page:

From the user’s perspective, every X server has a display name of the form:

hostname:displaynumber.screennumber

This information is used by the application to determine how it should connect to the server and which screen it should use by default (on displays with multiple monitors):

hostname The hostname specifies the name of the machine to which the display is physically connected. If the hostname is not given, the most efficient way of communicating to a server on the same machine will be used. displaynumber The phrase “display” is usually used to refer to a collection of monitors that share a common keyboard and pointer (mouse, tablet, etc.). Most workstations tend to only have one keyboard, and therefore, only one display. Larger, multi-user systems, however, frequently have several displays so that more than one person can be doing graphics work at once. To avoid confusion, each display on a machine is assigned a display number (beginning at 0) when the X server for that display is started. The display number must always be given in a display name. screennumber Some displays share a single keyboard and pointer among two or more monitors. Since each monitor has its own set of windows, each screen is assigned a screen number (beginning at 0) when the X server for that display is started. If the screen number is not given, screen 0 will be used.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/47772.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

每日一题——第十四题

题目&#xff1a;输入一行数字&#xff0c;将其按升序输出&#xff0c;且奇数在前&#xff0c;偶数在后 #include<stdio.h>void bubbleSort(int* arr, int n); int main(){int n, i, input_nums;printf("请输入数字个数&#xff1a; ");scanf("%d",…

纠正和防止机器学习中的不公平现象

「AI秘籍」系列课程&#xff1a; 人工智能应用数学基础人工智能Python基础人工智能基础核心知识人工智能BI核心知识人工智能CV核心知识AI 进阶&#xff1a;企业项目实战 预处理、处理中、后处理方法和非定量方法 机器学习中的公平性是一个复杂的问题。更糟糕的是&#xff0c;负…

加密传输及相关安全验证:

1.1. 加密&#xff1a; 1.1.1. 对称加密&#xff1a; 特点&#xff1a;加解密用一个密钥&#xff0c;加解密效率高&#xff0c;速度快&#xff0c;有密钥交互的问题问题&#xff1a;双方如何交互对称密钥的问题&#xff0c;用非对称密钥的公钥加密对称密钥的混合加密方式常用…

[数据分析]脑图像处理工具

###############ATTENTION&#xff01;############### 非常需要注意软件适配的操作系统&#xff01;有些仅适用于Linux&#xff0c;可以点进各自软件手册查看详情。 需要自行查看支持的影像模态。 代码库和软件我没有加以区分。 不是专门预处理的博客&#xff01;&#xf…

C语言 底层逻辑详细阐述指针(一)万字讲解 #指针是什么? #指针和指针类型 #指针的解引用 #野指针 #指针的运算 #指针和数组 #二级指针 #指针数组

文章目录 前言 序1&#xff1a;什么是内存&#xff1f; 序2&#xff1a;地址是怎么产生的&#xff1f; 一、指针是什么 1、指针变量的创建及其意义&#xff1a; 2、指针变量的大小 二、指针的解引用 三、指针类型存在的意义 四、野指针 1、什么是野指针 2、野指针的成因 a、指…

深入理解TCP/IP协议:三次握手与四次挥手

以下是一篇关于TCP/IP握手和挥手过程的CSDN博客文章草稿&#xff1a; 摘要 TCP&#xff08;传输控制协议&#xff09;是互联网上使用最广泛的协议之一&#xff0c;它负责在网络中的两个主机之间提供可靠的、有序的和错误检测功能的数据传输。本文将详细介绍TCP的三次握手过程和…

《基于 Kafka + Quartz 实现时限质控方案》

&#x1f4e2; 大家好&#xff0c;我是 【战神刘玉栋】&#xff0c;有10多年的研发经验&#xff0c;致力于前后端技术栈的知识沉淀和传播。 &#x1f497; &#x1f33b; CSDN入驻不久&#xff0c;希望大家多多支持&#xff0c;后续会继续提升文章质量&#xff0c;绝不滥竽充数…

Activiti7+ SpringBoot+SpringMVC 开发

添加 Controller 类 代码如下&#xff1a; RestController public class MyController {Autowiredprivate ProcessRuntime processRuntime;Autowiredprivate TaskRuntime taskRuntime;Autowiredprivate SecurityUtil securityUtil; }实现任务完成 RequestMapping("test…

学习分布式事务遇到的小bug

一、介绍Seata 在处理分布式事务时我用到是Seata&#xff0c;Seata的事务管理中有三个重要的角色&#xff1a; TC (Transaction Coordinator) - 事务协调者&#xff1a;维护全局和分支事务的状态&#xff0c;协调全局事务提交或回滚。 TM (Transaction Manager) - 事务管理器…

从零开始学习cartographer源码 | 02.cartographer_ros—node_main.cc

从零开始学习cartographer源码 | 02.cartographer_ros—node_main.cc cartographer_ros程序的入口 main()函数程序的主函数Run()函数 特别&#xff08;防杠&#xff09;声明&#xff1a;《从零开始学习cartographer源码》系列文章仅仅是本人学习cartographer的学习笔记&#xf…

PHP pwn 学习 (2)

文章目录 A. 逆向分析A.1 基本数据获取A.2 函数逆向zif_addHackerzif_removeHackerzif_displayHackerzif_editHacker A.3 PHP 内存分配 A.4 漏洞挖掘B. 漏洞利用B.1 PHP调试B.2 exp 上一篇blog中&#xff0c;我们学习了一些PHP extension for C的基本内容&#xff0c;下面结合一…

Open3D Ransac算法拟合点云球面

目录 一、概述 二、代码实现 2.1关键函数 2.2完整代码 三、实现效果 3.1原始点云 3.2拟合后点云 前期试读&#xff0c;后续会将博客加入该专栏&#xff0c;欢迎订阅 Open3D点云算法与点云深度学习案例汇总&#xff08;长期更新&#xff09;-CSDN博客 一、概述 RANSAC&a…

【Chatgpt大语言模型医学领域中如何应用】

随着人工智能技术 AI 的不断发展和应用&#xff0c;ChatGPT 作为一种强大的自然语言处理技术&#xff0c;无论是 自然语言处理、对话系统、机器翻译、内容生成、图像生成&#xff0c;还是语音识别、计算机视觉等方面&#xff0c;ChatGPT 都有着广泛的应用前景。特别在临床医学领…

python 语法学习 day6

一.编程题错题反思 1.计算分段函数&#xff1a; x float(input()) if x 0: res 0 else: res 1 / (2 * x) print("g({:.3f}) {:.3f}".format(x, res)) #其中对于f&#xff0c;e和%格式&…

pycharm如何debug for循环里面的错误值

一般debug时&#xff0c;在for循环里面的话&#xff0c;需要自己一步一步点。如果循环几百次那种就比较麻烦。此时可以采用try except的方式来解决 例子如下 #ptyhon debug for循环的代码 num[1,2,3,s,4] ans0 for i in num:try:ansiexcept:print(错误) print(ans) 结果如下&a…

HTML+echarts.js实现的炫酷金色风格可视化组件

模板下载地址&#xff1a; 炫酷金色风格可视化组件 (bootstrapmb.com)https://www.bootstrapmb.com/item/14888 一款炫酷金色风格可视化组件&#xff0c;统计图表使用Echarts.js&#xff0c;整体风格采用金黄色看起来很大气&#xff0c;设计是通用型的&#xff0c;可以用作任…

自动驾驶系列—智能巡航辅助功能中的横向避让功能介绍

文章目录 1. 背景介绍2. 功能定义3. 功能原理4. 传感器架构5. 实际应用案例5.1 典型场景1&#xff1a;前方车辆压线5.2 典型场景2&#xff1a;相邻车道有大型车辆5.3 典型场景3&#xff1a;它车近距离cut in 6. 总结与展望 1. 背景介绍 随着汽车技术的发展&#xff0c;智能巡航…

springboot开发实用篇

一、Mongodb &#xff08;1&#xff09;简介 MongoDB是一个开源、高性能、无模式的文档型数据库。NoSQL数据库产品中的一种&#xff0c;是最像关系型数据库的非关系型数据库。 数据库&#xff1a;永久性存储&#xff0c;修改频率极低 Mongodb&#xff1a;永久性存储与临时存…

Cxx Primer-Chap4

表达式可以没有操作符&#xff0c;但一定有操作数&#xff1a;理解表达式中含有多个操作符时涉及操作符的优先级、关联性以及操作数的计算顺序&#xff1a;如果操作符需要的操作数类型不同&#xff0c;则会发生一些默认的类型转换&#xff1a;什么叫Overloaded Operators&#…

跨平台应用进程cpu与内存监控的搭建说明

1. 前言: 随着科技的进步,互联网发展,能网上办理的就网上办理,按装一个app客户端,连接后台服务,只要是有网络就OK.便捷,快速,省事.但随之而来的是pc端上安装的应用越来越多,系统资源越来越不够用.这也一定程度上对应用程序有一定的要求,除了实现其功能外,性能也是需要关注的. …