Linux interview questions and answers (version 2022) are suitable for fresh students and experienced programmers. Each is a carefully screened high-frequency interview question to help you find a satisfactory job!
Linux
Download link: All interview questions and answers PDF
1. How many physical CPUs and the number of cores of each CPU in the current Linux system?
[root@centos6 ~ 10:55 #35]# cat /proc/cpuinfo|grep -c 'physical id' 4 [root@centos6 ~ 10:56 #36]# cat /proc/cpuinfo|grep -c 'processor' 4
2. There are two common commands for viewing system load. Which two are they? What do these three values mean?
[root@centos6 ~ 10:56 #37]# w 10:57:38 up 14 min, 1 user, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0 192.168.147.1 18:44 0.00s 0.10s 0.00s w [root@centos6 ~ 10:57 #38]# uptime 10:57:47 up 14 min, 1 user, load average: 0.00, 0.00, 0.00
load average is the system load, and the three values represent the average load of the system in one minute, five minutes and fifteen minutes respectively, that is, the average number of tasks.
3. What does vmstat R, B, Si, so, Bi, Bo mean?
[root@centos6 ~ 10:57 #39]# vmstat procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 0 0 0 1783964 13172 106056 0 0 29 7 15 11 0 0 99 0 0
r is running, indicating the number of running tasks
b is blocked, indicating the number of blocked tasks
si indicates how much data is read into memory from the swap partition
so indicates how much data is written from memory to the swap partition
bi indicates how much data is read from disk into memory
bo indicates how much data is written from memory to disk
Abbreviation:
i --input,Enter memory o --output,Out of memory s --swap,Swap partition b --block,Block device, disk All units are KB
4. In Linux system, do you know how to distinguish buffer from cache?
Both buffer and cache are an area in memory. When the CPU needs to write data to the disk, because the disk speed is relatively slow, the CPU saves the data into the buffer first, and then the CPU performs other tasks. The data in the buffer will be written to the disk regularly; When the CPU needs to read data from the disk, due to the slow speed of the disk, the data to be used can be stored in the cache in advance. It is much faster for the CPU to get data directly from the cache.
5. When using top to view system resource usage, which column indicates memory usage?
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 301 root 20 0 0 0 0 S 0.3 0.0 0:00.08 jbd2/sda3-8 1 root 20 0 2900 1428 1216 S 0.0 0.1 0:01.28 init 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
VIRT virtual memory usage
RES physical memory usage
SHR shared memory usage
%MEM memory usage
6. How to check the network card traffic in real time? How to view historical network card traffic?
Install the sysstat package and use the sar command to view it.
yum install -y sysstat#Install the sysstat package and obtain the sar command sar -n DEV#Check the network card traffic. It is updated every 10 minutes by default sar -n DEV 1 10#Display once a second, a total of 10 times sar -n DEV -f /var/log/sa/sa22#View the traffic log on the specified date
7. How to view the processes in the current system?
ps -aux or ps -elf
[root@centos6 ~ 13:20 #56]# ps -aux Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 2900 1428 ? Ss 10:43 0:01 /sbin/init root 2 0.0 0.0 0 0 ? S 10:43 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S 10:43 0:00 [migration/0] root 4 0.0 0.0 0 0 ? S 10:43 0:00 [ksoftirqd/0] ...... [root@centos6 ~ 13:21 #57]# ps -elf F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 4 S root 1 0 0 80 0 - 725 - 10:43 ? 00:00:01 /sbin/init 1 S root 2 0 0 80 0 - 0 - 10:43 ? 00:00:00 [kthreadd] 1 S root 3 2 0 -40 - - 0 - 10:43 ? 00:00:00 [migration/0] 1 S root 4 2 0 80 0 - 0 - 10:43 ? 00:00:00 [ksoftirqd/0] 1 S root 5 2 0 -40 - - 0 - 10:43 ? 00:00:00 [migration/0]
8.ps when viewing system processes, one column is stat. what does it mean if the stat of the current process is Ss? What does Z mean?
S means sleeping; S represents the main process; Z represents zombie process.
9. How to view which ports are opened in the system?
[root@centos6 ~ 13:20 #55]# netstat -lnp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1035/sshd tcp 0 0 :::22 :::* LISTEN 1035/sshd udp 0 0 0.0.0.0:68 0.0.0.0:* 931/dhclient Active UNIX domain sockets (only servers) Proto RefCnt Flags Type State I-Node PID/Program name Path unix 2 [ ACC ] STREAM LISTENING 6825 1/init @/com/ubuntu/upstart unix 2 [ ACC ] STREAM LISTENING 8429 1003/dbus-daemon /var/run/dbus/system_bus_socket
10. How to view the network connection status?
[root@centos6 ~ 13:22 #58]# netstat -an Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 192.168.147.130:22 192.168.147.1:23893 ESTABLISHED tcp 0 0 :::22 :::* LISTEN udp 0 0 0.0.0.0:68 0.0.0.0:* ......
11. Which configuration file do you need to edit to modify the ip? After modifying the configuration file, how to restart the network card to make the configuration effective?
Use the vi or vim editor to edit the network card configuration file / etc / sysconfig / network scripts / ifcft-eth0 (if eth1, the file name is ifcft-eth1), as follows:
DEVICE=eth0 HWADDR=00:0C:29:06:37:BA TYPE=Ethernet UUID=0eea1820-1fe8-4a80-a6f0-39b3d314f8da ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static IPADDR=192.168.147.130 NETMASK=255.255.255.0 GATEWAY=192.168.147.2 DNS1=192.168.147.2 DNS2=8.8.8.8
After modifying the network card, you can restart the network card with the command:
ifdown eth0 ifup eth0
You can also restart the network service:
service network restart
12. Can you configure multiple IP S for a network card? If yes, how?
You can configure multiple IP S for a network card. The configuration steps are as follows:
cat /etc/sysconfig/network-scripts/ifcfg-eth0#View the configuration of eth0 DEVICE=eth0 HWADDR=00:0C:29:06:37:BA TYPE=Ethernet UUID=0eea1820-1fe8-4a80-a6f0-39b3d314f8da ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static IPADDR=192.168.147.130 NETMASK=255.255.255.0 GATEWAY=192.168.147.2 DNS1=192.168.147.2 DNS2=8.8.8.8 (1)Create a new ifcfg-eth0:1 file cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:1 (2)Amend to read as follows: vim /etc/sysconfig/network-scripts/ifcfg-eth0:1 DEVICE=eth0:1 HWADDR=00:0C:29:06:37:BA TYPE=Ethernet UUID=0eea1820-1fe8-4a80-a6f0-39b3d314f8da ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static IPADDR=192.168.147.133 NETMASK=255.255.255.0 GATEWAY=192.168.147.2 DNS1=192.168.147.2 DNS2=8.8.8.8 (3)Restart network service: service network restart
13. How to check whether a network card is connected to a switch?
MII tool eth0 or MII tool eth1
14. How to view and modify the host name of the current host? Which configuration file needs to be modified to take effect after restart?
View host name:
hostname centos6.5
Modify host name:
hostname centos6.5-1 The configuration file needs to be modified for permanent effect: vim /etc/sysconfig/network NETWORKING=yes HOSTNAME=centos6.5-1
15. Which configuration file needs to be modified to set DNS?
(1) Set DNS in the file / etc/resolv.conf
(2) Set DNS in the file / etc / sysconfig / network scripts / ifcfg-eth0