Understanding /proc/cpuinfo in CentOS
The /proc/cpuinfo file is a virtual file generated by the Linux kernel that provides detailed information about the system’s CPU(s), including model name, core count, thread count, frequency, and cache size. It is read-only—modifying it directly can lead to system instability or failure. For most users, viewing this file is sufficient to understand CPU configuration.
Key Commands for Viewing CPU Information
To efficiently retrieve specific CPU details, use these command-line tools:
lscpu: A user-friendly command that summarizes CPU architecture (e.g., x86_64), physical sockets, cores per socket, threads per core, and CPU frequency. It’s ideal for quick overviews.cat /proc/cpuinfo: Displays raw, detailed CPU information. Combine with grep to filter specific data:
grep "model name" /proc/cpuinfo | uniq (shows unique model names).grep -c ^processor /proc/cpuinfo (total logical processors).grep "physical id" /proc/cpuinfo | sort | uniq | wc -l (unique physical CPU IDs).dmidecode: Provides hardware-level details (requires root). Use sudo dmidecode -t processor to get CPU model, socket count, and manufacturer.Adjusting CPU Performance Settings
While you can’t modify /proc/cpuinfo, you can optimize CPU behavior using these tools:
cpufrequtils: Adjust CPU frequency scaling to balance performance and power usage. Install it with sudo yum install cpufrequtils. Common commands:
sudo cpufreq-set -g performance.sudo cpufreq-set -c 0 -f 2.0GHz./proc/sys/kernel/irqaffinity to disable CPU节能模式 (set to “performance”) or enable it (set to “powersave”). Apply changes with sysctl -p.Limiting CPU Usage for Processes
To prevent a process from consuming excessive CPU resources, use cpulimit (install via sudo yum install cpulimit). For example, to limit process ID 1234 to 50% CPU usage: cpulimit -p 1234 -l 50. This is useful for maintaining system stability under heavy load.
Sharing CPU Information Securely
If you need to share CPU details with other systems or users, use these methods:
lscpu > cpu_info.txt to save CPU info to a file, then copy it via SCP/FTP.sudo yum install samba), configure /etc/samba/smb.conf to share the CPU info file (e.g., [CPUInfo] path = /path/to/cpu_info.txt read only = yes guest ok = yes), and restart Samba (sudo systemctl restart smb)./var/www/html/) and access it via browser.