在Linux操作系统中,/proc 是一个虚拟的目录,它是系统内存的映射,我们可以通过直接访问这个目录来获取系统信息,例如我们可以使用 cat /proc/cpuinfo 查看CPU信息。然而在macOSX系统中,由于系统实现机制的原因,并没有提供此功能,所以此命令不可用。
为了实现此功能,我们直接查看系统信息,也可以使用一些命令获得系统的基本硬件信息,如:
haodeMacBook-Pro:java hao$ system_profiler SPHardwareDataTypeHardware: Hardware Overview: Model Name: MacBook Pro Model Identifier: MacBookPro15,1 Processor Name: Intel Core i7 Processor Speed: 2.2 GHz Number of Processors: 1 Total Number of Cores: 6 L2 Cache (per Core): 256 KB L3 Cache: 9 MB Memory: 32 GB Boot ROM Version: 220.240.2.0.0 (iBridge: 16.16.3133.0.0,0) Serial Number (system): C02X606NJGH5 Hardware UUID: B0D3DA8E-4C62-53A7-893F-67611180EEC2但是,这些信息过于简单,如果我们需要更详细的信息,如CPU的型号信息,或者线程数就无能为力了。
不过好在系统提供了另外一个可能的命令 sysctl,如:
$ sysctl machdep.cpu.brand_string 返回CPU品牌信息。除了可以使用参数 machdep.cpu.brand_string 查看CPU品牌信息,以下列出所有可用参数,并附上在我的 MacBook Pro 2018上的输出结果。
以下为详细列表
hw.activecpu: 12hw.busfrequency: 400000000hw.busfrequency_max: 400000000hw.busfrequency_min: 400000000hw.byteorder: 1234hw.cacheconfig: 12 2 2 12 0 0 0 0 0 0hw.cachelinesize: 64hw.cachesize: 34359738368 32768 262144 9437184 0 0 0 0 0 0hw.cpu64bit_capable: 1hw.cpufamily: 260141638hw.cpufrequency: 2200000000hw.cpufrequency_max: 2200000000hw.cpufrequency_min: 2200000000hw.cpusubtype: 8hw.cputhreadtype: 1hw.cputype: 7hw.l1dcachesize: 32768hw.l1icachesize: 32768hw.l2cachesize: 262144hw.l3cachesize: 9437184hw.logicalcpu: 12hw.logicalcpu_max: 12hw.memsize: 34359738368hw.ncpu: 12hw.packages: 1hw.pagesize: 4096hw.physicalcpu: 6hw.physicalcpu_max: 6hw.tbfrequency: 1000000000kern.argmax: 262144kern.bootargs: kern.boottime: { sec = 1555831007, usec = 348628 } Sun Apr 21 15:16:47 2023kern.clockrate: { hz = 100, tick = 10000, tickadj = 0, profhz = 100, stathz = 100 }kern.coredump: 1kern.corefile: /cores/core.%Pkern.flush_cache_on_write: 0kern.hostid: 0kern.hostname: haodeMacBook-Pro.localkern.job_control: 1kern.maxfiles: 98304kern.maxfilesperproc: 49152kern.maxnbuf: 16384kern.maxproc: 4256kern.maxprocperuid: 2837kern.maxvnodes: 263168kern.msgbuf: 16384kern.nbuf: 16384kern.netboot: 0kern.ngroups: 16kern.nisdomainname: kern.num_files: 5645kern.num_tasks: 8192kern.num_taskthreads: 8192kern.num_threads: 40960kern.num_vnodes: 263168kern.nx: 1kern.osrelease: 18.2.0kern.osrevision: 199506kern.ostype: Darwinkern.osversion: 18D109kern.posix1version: 200112kern.procname: sysctlkern.safeboot: 0kern.saved_ids: 1kern.secure_kernel: 0kern.securelevel: 0kern.singleuser: 0kern.sleeptime: { sec = 1558779450, usec = 38866 } Sat May 25 18:17:30 2023kern.slide: 1kern.stack_depth_max: 10704kern.stack_size: 16384kern.sugid_coredump: 0kern.sugid_scripts: 0kern.usrstack: -433528832kern.usrstack64: 140732759859200kern.uuid: 1970B070-E53F-3178-83F3-1B95FA340695kern.version: Darwin Kernel Version 18.2.0: Thu Dec 20 20:46:53 PST 2018; root:xnu-4903.241.1~1/RELEASE_X86_64kern.waketime: { sec = 1558779640, usec = 668566 } Sat May 25 18:20:40 2023machdep.cpu.address_bits.physical: 39machdep.cpu.address_bits.virtual: 48machdep.cpu.brand: 0machdep.cpu.brand_string: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHzmachdep.cpu.cache.L2_associativity: 4machdep.cpu.cache.linesize: 64machdep.cpu.cache.size: 256machdep.cpu.core_count: 6machdep.cpu.cores_per_package: 8machdep.cpu.extfamily: 0machdep.cpu.extfeature_bits: 1241984796928machdep.cpu.extfeatures: SYSCALL XD 1GBPAGE EM64T LAHF LZCNT PREFETCHW RDTSCP TSCImachdep.cpu.extmodel: 9machdep.cpu.family: 6machdep.cpu.feature_bits: 9221959987971750911machdep.cpu.features: FPU VME DE PSE TSC MSR PAE MCE CX8 APIC SEP MTRR PGE MCA CMOV PAT PSE36 CLFSH DS ACPI MMX FXSR SSE SSE2 SS HTT TM PBE SSE3 PCLMULQDQ DTES64 MON DSCPL VMX EST TM2 SSSE3 FMA CX16 TPR PDCM SSE4.1 SSE4.2 x2APIC MOVBE POPCNT AES PCID XSAVE OSXSAVE SEGLIM64 TSCTMR AVX1.0 RDRAND F16Cmachdep.cpu.leaf7_feature_bits: 43804591machdep.cpu.leaf7_features: SMEP ERMS RDWRFSGS TSC_THREAD_OFFSET BMI1 AVX2 BMI2 INVPCID SMAP RDSEED ADX IPT SGX FPU_CSDS MPX CLFSOPTmachdep.cpu.logical_per_package: 16machdep.cpu.max_basic: 22machdep.cpu.max_ext: 2147483656machdep.cpu.microcode_version: 150machdep.cpu.model: 158machdep.cpu.processor_flag: 5machdep.cpu.signature: 591594machdep.cpu.stepping: 10machdep.cpu.thread_count: 12machdep.cpu.tlb.data.small: 64machdep.cpu.tlb.data.small_level1: 64machdep.cpu.tlb.inst.large: 8machdep.cpu.vendor: GenuineIntelmachdep.cpu.xsave.extended_state: 31 832 1088 0machdep.tsc.deep_idle_rebase: 1machdep.tsc.frequency: 2208000000machdep.tsc.nanotime.generation: 840machdep.tsc.nanotime.shift: 0net.inet.ip.forwarding: 0net.inet.ip.portrange.first: 49152net.inet.ip.portrange.hifirst: 49152net.inet.ip.portrange.hilast: 65535net.inet.ip.portrange.last: 65535net.inet.ip.portrange.lowfirst: 1023net.inet.ip.portrange.lowlast: 600net.inet.ip.redirect: 1net.inet.ip.ttl: 64net.inet.udp.checksum: 1net.inet.udp.maxdgram: 9216vm.loadavg: { 1.66 1.62 1.58 }vm.swapusage: total = 4096.00M used = 2860.00M free = 1236.00M (encrypted)user.bc_base_max: 99user.bc_dim_max: 2048user.bc_scale_max: 99user.bc_string_max: 1000user.coll_weights_max: 2user.cs_path: /usr/bin:/bin:/usr/sbin:/sbinuser.expr_nest_max: 32user.line_max: 2048user.posix2_c_bind: 0user.posix2_c_dev: 0user.posix2_char_term: 0user.posix2_fort_dev: 0user.posix2_fort_run: 0user.posix2_localedef: 0user.posix2_sw_dev: 0user.posix2_upe: 0user.posix2_version: 200112user.re_dup_max: 255user.stream_max: 20user.tzname_max: 255