Read data in /proc/ folder
I would like to get CPU model name and number of cores in Linux system. This informations are in /proc/cpuinfo file, for imagination cpuinfo folder looks like:
processor : 0 vendor_id : GenuineIntel cpu family : 15 model : 2 model name : Intel(R) Xeon(TM) CPU 2.40GHz stepping : 7 cpu MHz : 2392.371 cache size : 512 KB physical id : 0 siblings : 2 cpu cores : 4 runqueue : 0 fdiv_bug : no hlt_bug : no f00f_bug : no coma_bug : no fpu : yes fpu_exception : yes cpuid level : 2 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm bogomips : 4771.02
So I want to get "model name" and "cpu cores". My idea is to read that file line by line and if line contains "model name" then I split that line by ":" and result is second string, same approach for "cpu cores". Is this approach good? Should I use contains or rather Regexp?
The search being not really complex, using contains should be just fine. Then you can split the line on the colon to get the value you are looking for.
ok, thank you :)
You can also use startsWith since you are looking at the start of the line content.
Since it's seems the questions has been answered, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)