Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Read data in /proc/ folder
Forum Updated to NodeBB v4.3 + New Features

Read data in /proc/ folder

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    t0msk
    wrote on last edited by
    #1

    Hello,

    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?

    Thank you

    Student who loves C/C++

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • T Offline
        T Offline
        t0msk
        wrote on last edited by
        #3

        ok, thank you :)

        Student who loves C/C++

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved