{"id":186944,"date":"2013-07-17T21:25:03","date_gmt":"2013-07-17T17:25:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=186944"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=186944","title":{"rendered":"<span class=\"post_title\">\u041f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u043c\u043e\u043d\u0438\u0442\u043e\u0440<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t<habracut\/>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043e\u043f\u0438\u0448\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0430. \u0414\u0430\u043d\u043d\u044b\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u043c\u043e\u043d\u0438\u0442\u043e\u0440 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442:  <\/p>\n<ul>\n<li>Hostname<\/li>\n<li>\u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/li>\n<li>Uptime<\/li>\n<li>\u0418\u043c\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430<\/li>\n<li>\u0427\u0430\u0441\u0442\u043e\u0442\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430<\/li>\n<li>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430<\/li>\n<li>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438<\/li>\n<li>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0431\u0435\u0437 \u043a\u044d\u0448\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/li>\n<li>\u0417\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b<\/li>\n<\/ul>\n<p>  \u0415\u0441\u043b\u0438 \u043a\u043e\u043c\u0443-\u0442\u043e \u0432 \u043f\u0440\u0435\u0434\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u043f\u0443\u043d\u0442\u043a\u0435 \u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u0431\u0435\u0437 \u043a\u044d\u0448\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0432\u043e\u0442 <a href=\"https:\/\/wiki.archlinux.org\/index.php\/FAQ_(%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9)#.D0.92.29_.D0.9F.D0.BE.D1.87.D0.B5.D0.BC.D1.83_Arch_.D0.B8.D1.81.D0.BF.D0.BE.D0.BB.D1.8C.D0.B7.D1.83.D0.B5.D1.82_.D0.B2.D1.81.D1.8E_.D0.BE.D0.BF.D0.B5.D1.80.D0.B0.D1.82.D0.B8.D0.B2.D0.BD.D1.83.D1.8E_.D0.BF.D0.B0.D0.BC.D1.8F.D1.82.D1.8C.3F\">\u044d\u0442\u043e<\/a>, \u0442\u0430\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442. \u0422\u0430\u043a\u0436\u0435 \u0432 \u044d\u0442\u043e\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u043c \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432. <br \/>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443 \u043d\u0430\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u043c\u043e\u043d\u0438\u0442\u043e\u0440:<br \/>  <img decoding=\"async\" src=\"http:\/\/cs412630.vk.me\/v412630985\/3116\/yjxv6Fmzy0A.jpg\" alt=\"image\"\/><img decoding=\"async\" src=\"http:\/\/cs412630.vk.me\/v412630985\/310f\/PpG3ByJvaVQ.jpg\" alt=\"image\"\/><br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b, \u0438 \u044f \u043c\u043e\u0433\u0443 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043a \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043e\u0434\u0430, \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0430\u044e \u0441\u0440\u0430\u0437\u0443 \u0447\u0442\u043e \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043b\u0438\u043d\u0443\u043a\u0441\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u0435\u0433\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u044b \u043d\u0430 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0435 \u043f\u0430\u043f\u043a\u0438 \/proc. \u0421\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u043c\u043e\u043d\u0438\u0442\u043e\u0440 \u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043b \u043d\u0430 \u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430, \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u0449\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f, \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u043d\u0443 \u0438 \u0442\u0440\u0435\u0442\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0442 \u044d\u0442\u043e \u0432 \u043e\u0434\u043d\u043e \u0446\u0435\u043b\u043e\u0435. \u0412\u043e\u0442 \u043a\u0430\u0440\u043a\u0430\u0441 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u044f \u0435\u0433\u043e \u043d\u0430\u0437\u0432\u0430\u043b Info:  <\/p>\n<pre><code class=\"cpp\">#ifndef INFO_H #define INFO_H  #include &lt;QtGui&gt; #include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;pwd.h&gt; #include &lt;unistd.h&gt; #include &lt;sys\/sysinfo.h&gt; #include &lt;vector&gt; using namespace std; class Info : public QWidget {     Q_OBJECT public:     explicit Info(QWidget *parent = 0); private:     QLabel       * hostname;     QLabel       * user;     QLabel       * uptime;     QLabel       * proc;     QLabel       * freq;     QLabel       * cpuload;     QLabel       * mem;     QLabel       * memload;     QProgressBar * cpubar;     QProgressBar * membar;     QVBoxLayout  * layout;     QHBoxLayout  * hlayout;     vector&lt;float&gt; readCpuStats();     int getCpuLoad(double dt); public slots:     void update(); };  #endif \/\/ INFO_H <\/code><\/pre>\n<p>  \u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b pwd.h \u0438 unistd.h \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043c\u0435\u043d\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b sys\/sysinfo.h \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0430\u043f\u0442\u0430\u0439\u043c\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u0438\u0448\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430 Info, \u043e\u043d\u0430 \u0440\u0430\u0441\u043f\u043e\u043b\u0433\u0430\u0435\u0442\u0441\u044f \u0432 \u0444\u0430\u0439\u043b\u0435 info.cpp. \u0412 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u0444\u0430\u0439\u043b\u0430 info.cpp \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c info.h(\u043a\u0430\u0440\u043a\u0430\u0441 \u043a\u043b\u0430\u0441\u0441\u0430 info). \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 Info \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:  <\/p>\n<pre><code class=\"cpp\">Info::Info(QWidget *parent) :     QWidget(parent) {     hostname   = new QLabel(&quot;Hostname: &quot;);     user       = new QLabel(&quot;\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c: &quot;);     uptime     = new QLabel(&quot;Uptime: &quot;);     proc       = new QLabel(&quot;\u041f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440: &quot;);     freq       = new QLabel(&quot;\u0427\u0430\u0441\u0442\u043e\u0442\u0430:&quot;);     cpuload    = new QLabel(&quot;\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430: &quot;);     mem        = new QLabel(&quot;\u041e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c: &quot;);     memload    = new QLabel(&quot;\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c: &quot;);     cpubar     = new QProgressBar;     membar     = new QProgressBar;     layout     = new QVBoxLayout;     hlayout    = new QHBoxLayout;      cpubar-&gt;setMaximumHeight(21); membar-&gt;setMaximumHeight(21);     hlayout-&gt;addWidget(cpuload); hlayout-&gt;addWidget(cpubar);     layout-&gt;addWidget(hostname); layout-&gt;addWidget(user);     layout-&gt;addWidget(uptime); layout-&gt;addWidget(proc);     layout-&gt;addWidget(freq); layout-&gt;addLayout(hlayout);     layout-&gt;addWidget(mem); layout-&gt;addWidget(memload);     layout-&gt;addWidget(membar); setLayout(layout);      update();      QTimer *timer = new QTimer;     connect(timer, SIGNAL(timeout()), this, SLOT(update()));     timer-&gt;start(2000); } <\/code><\/pre>\n<p>  \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u043c\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435\u043c \u043c\u044b \u0440\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u043b\u044d\u0439\u0430\u0443\u0442\u0430\u0445. \u041f\u043e\u0441\u043b\u0435 \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043b\u043e\u0442 update \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u043c\u0435\u0442\u043a\u0438 \u0438 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u0431\u0430\u0440\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043b\u0438\u0441\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438. \u0427\u0442\u043e\u0431\u044b \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u043b\u0430\u0441\u044c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 QTimer, \u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0435\u0433\u043e \u0441\u0438\u0433\u043d\u0430\u043b timeout, \u0441 \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u043c \u043d\u0430\u043c \u0441\u043b\u043e\u0442\u043e\u043c update. <br \/>  \u0414\u0443\u043c\u0430\u044e \u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0441\u043b\u043e\u0442 update, \u0432\u043e\u0442 \u0435\u0433\u043e \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"cpp\">void Info::update() {     ifstream stream(&quot;\/proc\/sys\/kernel\/hostname&quot;); string str;     getline(stream,str);     hostname-&gt;setText(&quot;Hostname: &quot; + QString::fromStdString(str));     passwd *pw;     uid_t uid;     uid = geteuid();     pw = getpwuid(uid);     user-&gt;setText(&quot;\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c: &quot; + QString::fromAscii(pw-&gt;pw_name));     struct sysinfo o;     sysinfo(&o);     long up = o.uptime;     int hour = up\/60\/60;     int min = (up - hour*60*60) \/ 60;     int sec =  ((up - hour*60*60) - min*60);     QString e = QString::number(hour) +  QString(&quot; h. &quot;) + QString::number(min) + QString(&quot; m. &quot;)                 + QString::number(sec) + QString(&quot; s.&quot;);     uptime-&gt;setText(&quot;Uptime: &quot; + e);     stream.close(); stream.open(&quot;\/proc\/cpuinfo&quot;);     stream &gt;&gt; str;     for(int i = 0; i &lt; 15;i++) stream &gt;&gt; str;     getline(stream,str);     proc-&gt;setText(&quot;\u041f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440: &quot; + QString::fromStdString(str));     for(int i = 0; i&lt; 7; i++)  stream &gt;&gt; str;     freq-&gt;setText(&quot;\u0427\u0430\u0441\u0442\u043e\u0442\u0430: &quot; + QString::fromStdString(str) + &quot; MHz&quot;);     cpubar-&gt;setValue(getCpuLoad(0.3));     stream.close(); stream.open(&quot;\/proc\/meminfo&quot;);     stream &gt;&gt; str; stream &gt;&gt; str;     int num = atoi(str.c_str());     int percent = num \/ 100;     int gb = (num \/ 1024) \/ 1024;     int mb = (num-gb*1024*1024) \/1024;     int kb = (num - (gb*1024*1024+mb*1024));     e = QString::number(gb) + QString(&quot; Gb &quot;) + QString::number(mb) + QString(&quot; Mb &quot;)         + QString::number(kb) + QString(&quot; Kb&quot;);     mem-&gt;setText(&quot;\u041e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c: &quot; + e);     stream &gt;&gt; str; stream &gt;&gt; str; stream &gt;&gt; str;     int free = atoi(str.c_str());     stream &gt;&gt; str; stream &gt;&gt; str; stream &gt;&gt; str;     free += atoi(str.c_str());     stream &gt;&gt; str; stream &gt;&gt; str; stream &gt;&gt; str;     free += atoi(str.c_str());     num -= free;     gb = num \/ 1024 \/ 1024;     mb = (num - gb*1024*1024) \/ 1024;     kb = (num - ((mb*1024) + (gb * 1024 * 1024)));     if (gb != 0 )     {         e = QString::number(gb) + &quot; Gb &quot; + QString::number(mb) + QString(&quot; Mb &quot;) + QString::number(kb)                + QString(&quot; Kb&quot;);     } else     {         e = QString::number(mb) + QString(&quot; Mb &quot;) + QString::number(kb) + QString(&quot; Kb&quot;);     }     memload-&gt;setText(&quot;\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c: &quot; + e);     percent = num \/ percent; membar-&gt;setValue(percent); } <\/code><\/pre>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f(\u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0430 \u0441\u0443\u043f\u0435\u0440\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f) \u0444\u0430\u0439\u043b \/proc\/sys\/kernel\/hostname \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043c\u044f \u043c\u0430\u0448\u0438\u043d\u044b, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043c\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043c\u0435\u0442\u043a\u0443 hostname. \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b passwd \u0438 uid_t, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043a\u0438 user. \u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0442\u043e\u043c \u043a\u0430\u043a \u0443\u0437\u043d\u0430\u0442\u044c \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0431\u044b\u043b\u0430 \u0432\u0437\u044f\u0442\u0430 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b whoami. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b sysinfo, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0435\u0440\u0451\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u0430\u043f\u0442\u0430\u0439\u043c\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u0435. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043c\u044b \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a stream \u0441 \u0444\u0430\u0439\u043b\u043e\u043c \/proc\/cpuinfo, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u0438\u043c\u0435\u043d\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0438 \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u043e\u0442\u0435. \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 getCpuLoad, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u043e\u043f\u0438\u0448\u0443 \u043d\u0438\u0436\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u0442\u043e\u043a stream \u0441 \u0444\u0430\u0439\u043b\u043e\u043c \/proc\/meminfo \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0431\u0435\u0440\u0451\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, \u0438 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c \u0435\u0433\u043e \u043a \u0443\u0434\u043e\u0431\u043d\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u043c\u0443 \u0432\u0438\u0434\u0443. \u041f\u043e\u0442\u043e\u043c \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0436\u0435 \u0444\u0430\u0439\u043b\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043e\u0431\u044a\u0451\u043c \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u043d\u044f\u0442\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043c\u044b \u0432\u044b\u0447\u0438\u0442\u0430\u0435\u043c \u0438\u0437 \u0432\u0441\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043a\u0443 \u0438 \u043e\u0431\u044a\u0451\u043c \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0441\u043b\u0435 \u043e\u043f\u044f\u0442\u044c \u0436\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c \u043a \u0443\u0434\u043e\u0431\u043d\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u043c\u0443 \u0432\u0438\u0434\u0443. \u0422\u0435\u043f\u0435\u0440\u044c \u043a\u0430\u043a \u044f \u043e\u0431\u0435\u0449\u0430\u043b \u0432\u044b\u0448\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 getCpuLoad. \u042d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u044f \u043f\u0438\u0441\u0430\u043b \u043d\u0435 \u0441\u0430\u043c(\u044f \u0435\u0451 \u0432\u0437\u044f\u043b \u0432\u043e\u0442 <a href=\"http:\/\/0xc0dec.org\/2011\/06\/16\/cpp_linux_cpu_load\/\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a>), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0433\u043e \u0435\u0451 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u044f \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043d\u0435 \u043c\u043e\u0433\u0443, \u044f \u043e\u043f\u0438\u0448\u0443 \u0435\u0451 \u0432 \u043e\u0431\u0449\u0438\u0445 \u0447\u0435\u0440\u0442\u0430\u0445. \u0412\u043e\u0442 \u043e\u043d\u0430:  <\/p>\n<pre><code class=\"cpp\">int Info::getCpuLoad(double dt) {     vector&lt;float&gt; stats1 = readCpuStats();     QProcess::execute(&quot;sleep&quot;,QStringList() &lt;&lt; QString::number(dt));     vector&lt;float&gt; stats2 = readCpuStats();     int size1 = stats1.size();     int size2 = stats2.size();     if (!size1 || !size2 || size1 != size2) return 2;     for (int i = 0; i &lt; size1; ++i) stats2[i] -= stats1[i];     int sum = 1;     for (int i = 0; i &lt; size1; ++i) sum += stats2[i];     int load = 100 - (stats2[size2 - 1] * 100 \/ sum);     return load; } <\/code><\/pre>\n<p>  \u043c\u044b \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0440\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 readCpuStats(\u0435\u0451 \u044f \u0442\u043e\u0436\u0435 \u043e\u043f\u0438\u0448\u0443 \u043d\u0438\u0436\u0435), \u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u044b \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u043e\u043c \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u044d\u0442\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0410 \u0432\u043e\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 readCpuStats:  <\/p>\n<pre><code class=\"cpp\">vector&lt;float&gt; Info::readCpuStats() {     vector&lt;float&gt; ret;     ifstream stat_file(&quot;\/proc\/stat&quot;);     if (!stat_file.is_open())     {         cout &lt;&lt; &quot;Unable to open \/proc\/stat&quot; &lt;&lt; std::endl;         return ret;     }     int val;     string tmp;     stat_file &gt;&gt; tmp;     for (int i = 0; i &lt; 4; ++i)     {         stat_file &gt;&gt; val;         ret.push_back(val);     }     stat_file.close();     return ret; } <\/code><\/pre>\n<p>  \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u044b\u043b\u0430 \u0432\u0437\u044f\u0442\u0430 \u0441 \u0442\u043e\u0433\u043e \u0436\u0435 \u0441\u0430\u0439\u0442\u0430 \u0447\u0442\u043e \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f getCpuLoad. \u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \/proc\/stat, \u0438 \u0437\u0430\u043d\u043e\u0441\u0438\u043c \u0438\u0445 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0442\u043e\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c return.<br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043b\u0430\u0441\u0441 Info \u043d\u0430\u043f\u0438\u0441\u0430\u043d, \u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430 ProcessTable. \u0412\u043e\u0442 \u043a\u0430\u0440\u043a\u0430\u0441 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430:  <\/p>\n<pre><code class=\"cpp\">#ifndef PROCESSTABLE_H #define PROCESSTABLE_H  #include &lt;QtGui&gt; #include &lt;iostream&gt; #include &lt;fstream&gt; using namespace std; class ProcessTable : public QWidget {     Q_OBJECT public:     explicit ProcessTable(QWidget *parent = 0); private:     QTableWidget * table;     QHBoxLayout* hlayout;     QPushButton* button;     QVBoxLayout* layout; public slots:     void update();     void kill(); };  #endif \/\/ PROCESSTABLE_H <\/code><\/pre>\n<p>  \u0421\u043b\u043e\u0442 update \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0430 \u0441\u043b\u043e\u0442 kill \u0434\u043b\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432. \u0412 \u0444\u0430\u0439\u043b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u0441 \u0435\u0433\u043e \u043a\u0430\u0440\u043a\u0430\u0441\u043e\u043c. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0436\u0443 \u043a \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0432\u043e\u0442 \u043a\u043e\u0434 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430:  <\/p>\n<pre><code class=\"cpp\">ProcessTable::ProcessTable(QWidget *parent) :     QWidget(parent) {     hlayout = new QHBoxLayout;     button = new QPushButton(&quot;\u0417\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c&quot;);     button-&gt;setToolTip(&quot;\u0414\u043b\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0435\u0433\u043e PID \u0438 \u043d\u0430\u0436\u0430\u0442\u044c \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \\&quot;\u0417\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c\\&quot;&quot;);     connect(button,SIGNAL(clicked()),this,SLOT(kill()));     hlayout-&gt;addStretch();     hlayout-&gt;addWidget(button);     layout = new QVBoxLayout;     table = new QTableWidget;     update();     layout-&gt;addWidget(table);     layout-&gt;addLayout(hlayout);     this-&gt;setLayout(layout);     QTimer *timer = new QTimer;     connect(timer, SIGNAL(timeout()), this, SLOT(update()));     timer-&gt;start(4000); } <\/code><\/pre>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u0438 \u043a\u043e\u043c\u043f\u0430\u043d\u0443\u0435\u043c \u0438\u0445, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0441\u0438\u0433\u043d\u0430\u043b clicked \u0443 \u043a\u043d\u043e\u043f\u043a\u0438 \u00ab\u0417\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c\u00bb \u0441\u043e \u0441\u043b\u043e\u0442\u043e\u043c \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u2014 kill. \u0422\u0430\u043a \u0436\u0435 \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043b\u043e\u0442 update \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0442\u0430\u0439\u043c\u0435\u0440\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u043b\u043e\u0442\u0430 update, \u0432\u043e\u0442 \u0435\u0433\u043e \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"cpp\">void ProcessTable::update() {     table-&gt;setColumnCount(2);     table-&gt;setRowCount(0);     QStringList list;     list &lt;&lt; &quot;Name&quot; &lt;&lt; &quot;PID&quot;;     table-&gt;setHorizontalHeaderLabels(list);     QDir * dir = new QDir(&quot;\/proc&quot;);     list = dir-&gt;entryList(QStringList(&quot;*&quot;),QDir::AllDirs);     foreach(QString str, list) {         if(str.toInt()) {             ifstream stream;              stream.open(&quot;\/proc\/&quot; + str.toAscii() + &quot;\/comm&quot;);             string s; getline(stream,s);             int lastRow = table-&gt;rowCount();             QString icon = &quot;\/usr\/share\/icons\/hicolor\/32x32\/apps\/&quot; + QString::fromStdString(s) + &quot;.png&quot;;             QFile file(icon);             table-&gt;insertRow(lastRow);             table-&gt;setColumnWidth(0,150);              if(!file.exists()) {                 icon = &quot;:\/binary.png&quot;;             }             table-&gt;setItem(lastRow,0,new QTableWidgetItem(QPixmap(icon),QString::fromStdString(s)));             table-&gt;setItem(lastRow,1,new QTableWidgetItem(str));         } else {             continue;         }     } } <\/code><\/pre>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0438 \u0441\u0442\u0440\u043e\u043a \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0438\u043c\u0435\u043d\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0439 \u0432 \u043f\u0430\u043f\u043a\u0435 \/proc. \u0414\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043c\u044b \u0446\u0438\u043a\u043b\u043e\u043c \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u043f\u043e \u0432\u0441\u0435\u043c\u0443 \u0441\u043f\u0438\u0441\u043a\u0443, \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c. \u0418\u043c\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \/proc\/pid\/comm. \u0418\u043a\u043e\u043d\u043a\u0443 \u043c\u044b \u0431\u0435\u0440\u0451\u043c \u0438\u0437 \u043f\u0430\u043f\u043a\u0438 \/usr\/share\/icons\/hicolor\/32&#215;32\/apps, \u0430 \u0435\u0441\u043b\u0438 \u0438\u043a\u043e\u043d\u043a\u0438 \u0442\u0430\u043c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u0448\u0438\u0442\u0430\u044f \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u0438\u043a \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 binary.png. \u0412\u043e\u0442 \u044d\u0442\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430:<br \/>  <img decoding=\"async\" src=\"http:\/\/cs412630.vk.me\/v412630985\/311d\/1R_5Wgmw1DA.jpg\" alt=\"image\"\/><br \/>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0448\u0438\u0442\u044c \u0435\u0451 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b rcc, \u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 rcc \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u043a\u043d\u0438\u0433\u0435 \u041c\u0430\u043a\u0441\u0430 \u0428\u043b\u0435\u0435 \u2014 \u00abQt \u2014 \u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 C++\u00bb, \u0438\u043b\u0438 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0433\u0443\u0433\u043b\u0438\u0442\u044c, \u044f \u0434\u0443\u043c\u0430\u044e \u0447\u0442\u043e \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u043c\u043d\u043e\u0433\u043e \u043c\u0430\u043d\u043e\u0432 \u043f\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e rcc.<br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0443 \u043a \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0441\u043b\u043e\u0442\u0430 kill, \u0432\u043e\u0442 \u0435\u0433\u043e \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"cpp\">void ProcessTable::kill() {     QList&lt;QTableWidgetItem*&gt; list = table-&gt;selectedItems();     QTableWidgetItem* item = list.value(0);     QString str = item-&gt;text();     QProcess::execute(&quot;kill&quot;, QStringList() &lt;&lt; str);     update(); } <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0435\u0441\u0442\u044c \u0432\u043e \u0432\u0441\u0435\u0445 \u043b\u0438\u043d\u0443\u043a\u0441\u0430\u0445(\u0435\u0441\u043b\u0438 \u0432 \u0432\u0430\u0448\u0435\u043c \u043b\u0438\u043d\u0443\u043a\u0441\u0435 \u0435\u0451 \u043d\u0435\u0442\u0443, \u0442\u043e \u044f \u0434\u0430\u0436\u0435 \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u0430 \u043b\u0438\u043d\u0443\u043a\u0441 \u0442\u0430\u043a\u043e\u0439), \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u044f \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0441\u044c \u043c\u0435\u0442\u043e\u0434\u043e\u043c execute \u043a\u043b\u0430\u0441\u0441\u0430 QProcess, \u0432\u0442\u043e\u0440\u043e\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u044d\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u044f \u043f\u0435\u0440\u0435\u0434\u0430\u044e \u0442\u043e\u043b\u044c\u043a\u043e PID \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c, \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u044f \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0451\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0438\u0441\u0447\u0435\u0437 \u0438\u0437 \u043d\u0435\u0451. \u0422\u0435\u043f\u0435\u0440\u044c \u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0436\u0443 \u043a \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430 SystemMonitor, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u044f \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e \u044d\u0442\u0438 \u0434\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430. \u041a\u0430\u0440\u043a\u0430\u0441 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439:  <\/p>\n<pre><code class=\"cpp\">#ifndef SYSTEMMONITOR_H #define SYSTEMMONITOR_H  #include &lt;QtGui&gt; #include &quot;info.h&quot; #include &quot;processtable.h&quot; class SystemMonitor : public QWidget {     Q_OBJECT public:     explicit SystemMonitor(QWidget *parent = 0); };  #endif \/\/ SYSTEMMONITOR_H <\/code><\/pre>\n<p>  \u041d\u0443, \u043c\u0435\u0442\u043e\u0434 \u0432 \u044d\u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0441\u0435\u0439\u0447\u0430\u0441 \u0435\u0433\u043e \u043e\u043f\u0438\u0448\u0443. \u0412\u043e\u0442 \u043a\u043e\u0434 \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430-\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430(\u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0444\u0430\u0439\u043b\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 \u043a\u0430\u0440\u043a\u0430\u0441\u0430):  <\/p>\n<pre><code class=\"cpp\">SystemMonitor::SystemMonitor(QWidget *parent) :     QWidget(parent) {     QTabWidget * tab = new QTabWidget;     Info* info = new Info;     ProcessTable* pt = new ProcessTable;     tab-&gt;addTab(info,&quot;\u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0441\u0438\u0441\u0442\u0435\u043c\u0435&quot;);     tab-&gt;addTab(pt,&quot;\u041f\u0440\u043e\u0446\u0435\u0441\u0441\u044b&quot;);     QVBoxLayout * layout = new QVBoxLayout;     layout-&gt;addWidget(tab);     this-&gt;setLayout(layout);     this-&gt;show(); } <\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0438\u0434\u0436\u0435\u0442 \u0432\u043a\u043b\u0430\u0434\u043e\u043a, \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u0443\u0434\u0430 \u043d\u0430\u0448 \u0432\u0438\u0434\u0436\u0435\u0442 \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439, \u0438 \u0432\u0438\u0434\u0436\u0435\u0442 \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439, \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0433\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u043c\u0435\u0442\u043e\u0434 addTab \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432\u0438\u0434\u0436\u0435\u0442, \u0442\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0438 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u044b Info \u0438 ProcessTable \u043e\u0442 QWidget. \u0418 \u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0448\u0442\u0440\u0438\u0448\u043e\u043a, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u0444\u0430\u0439\u043b\u0430 main.cpp. \u0412\u043e\u0442 \u0435\u0433\u043e \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"cpp\">#include &quot;systemmonitor.h&quot; int main(int argc,char** argv) {     QTextCodec::setCodecForLocale(QTextCodec::codecForName(&quot;UTF-8&quot;));     QTextCodec::setCodecForTr(QTextCodec::codecForName(&quot;UTF-8&quot;));     QTextCodec::setCodecForCStrings(QTextCodec::codecForName(&quot;UTF-8&quot;));     QApplication app(argc,argv);     QStyle * style = QStyleFactory::create(&quot;Cleanlooks&quot;);     app.setStyle(style);     SystemMonitor sys;     return app.exec(); } <\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0432\u044b\u0435 \u0442\u0440\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u0435\u043b\u0430\u044e\u0442 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0440\u0443\u0441\u0441\u043a\u0438\u0435 \u0431\u0443\u043a\u0432\u044b \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u043b\u0438\u0441\u044c. \u0421\u0442\u0440\u043e\u043a\u0438 8 \u0438 9 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0442 \u0447\u0442\u043e \u0432 \u043b\u044e\u0431\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e. <br \/>  \u041d\u0443 \u0432\u043e\u0442 \u0438 \u0432\u0441\u0451, \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u043c\u043e\u043d\u0438\u0442\u043e\u0440 \u0433\u043e\u0442\u043e\u0432, \u0412\u0441\u0435\u043c \u043f\u043e\u043a\u0430! \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/186944\/\"> http:\/\/habrahabr.ru\/post\/186944\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t<habracut\/>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043e\u043f\u0438\u0448\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0430. \u0414\u0430\u043d\u043d\u044b\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u043c\u043e\u043d\u0438\u0442\u043e\u0440 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442:  <\/p>\n<ul>\n<li>Hostname<\/li>\n<li>\u0418\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/li>\n<li>Uptime<\/li>\n<li>\u0418\u043c\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430<\/li>\n<li>\u0427\u0430\u0441\u0442\u043e\u0442\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430<\/li>\n<li>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430<\/li>\n<li>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438<\/li>\n<li>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0431\u0435\u0437 \u043a\u044d\u0448\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/li>\n<li>\u0417\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b<\/li>\n<\/ul>\n<p>  \u0415\u0441\u043b\u0438 \u043a\u043e\u043c\u0443-\u0442\u043e \u0432 \u043f\u0440\u0435\u0434\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u043f\u0443\u043d\u0442\u043a\u0435 \u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u0431\u0435\u0437 \u043a\u044d\u0448\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0432\u043e\u0442 <a href=\"https:\/\/wiki.archlinux.org\/index.php\/FAQ_(%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9)#.D0.92.29_.D0.9F.D0.BE.D1.87.D0.B5.D0.BC.D1.83_Arch_.D0.B8.D1.81.D0.BF.D0.BE.D0.BB.D1.8C.D0.B7.D1.83.D0.B5.D1.82_.D0.B2.D1.81.D1.8E_.D0.BE.D0.BF.D0.B5.D1.80.D0.B0.D1.82.D0.B8.D0.B2.D0.BD.D1.83.D1.8E_.D0.BF.D0.B0.D0.BC.D1.8F.D1.82.D1.8C.3F\">\u044d\u0442\u043e<\/a>, \u0442\u0430\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442. \u0422\u0430\u043a\u0436\u0435 \u0432 \u044d\u0442\u043e\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u043c \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432. <br \/>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443 \u043d\u0430\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u043c\u043e\u043d\u0438\u0442\u043e\u0440:<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b, \u0438 \u044f \u043c\u043e\u0433\u0443 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043a \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043e\u0434\u0430, \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0430\u044e \u0441\u0440\u0430\u0437\u0443 \u0447\u0442\u043e \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043b\u0438\u043d\u0443\u043a\u0441\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u0435\u0433\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u044b \u043d\u0430 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0435 \u043f\u0430\u043f\u043a\u0438 \/proc. \u0421\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u043c\u043e\u043d\u0438\u0442\u043e\u0440 \u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043b \u043d\u0430 \u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0430, \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u0449\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f, \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432, \u043d\u0443 \u0438 \u0442\u0440\u0435\u0442\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0442 \u044d\u0442\u043e \u0432 \u043e\u0434\u043d\u043e \u0446\u0435\u043b\u043e\u0435. \u0412\u043e\u0442 \u043a\u0430\u0440\u043a\u0430\u0441 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u044f \u0435\u0433\u043e \u043d\u0430\u0437\u0432\u0430\u043b Info:  <\/p>\n<pre><code class=\"cpp\">#ifndef INFO_H #define INFO_H  #include &lt;QtGui&gt; #include &lt;iostream&gt; #include &lt;fstream&gt; #include &lt;pwd.h&gt; #include &lt;unistd.h&gt; #include &lt;sys\/sysinfo.h&gt; #include &lt;vector&gt; using namespace std; class Info : public QWidget {     Q_OBJECT public:     explicit Info(QWidget *parent = 0); private:     QLabel       * hostname;     QLabel       * user;     QLabel       * uptime;     QLabel       * proc;     QLabel       * freq;     QLabel       * cpuload;     QLabel       * mem;     QLabel       * memload;     QProgressBar * cpubar;     QProgressBar * membar;     QVBoxLayout  * layout;     QHBoxLayout  * hlayout;     vector&lt;float&gt; readCpuStats();     int getCpuLoad(double dt); public slots:     void update(); };  #endif \/\/ INFO_H <\/code><\/pre>\n<p>  \u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b pwd.h \u0438 unistd.h \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043c\u0435\u043d\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b sys\/sysinfo.h \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0430\u043f\u0442\u0430\u0439\u043c\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u0438\u0448\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430 Info, \u043e\u043d\u0430 \u0440\u0430\u0441\u043f\u043e\u043b\u0433\u0430\u0435\u0442\u0441\u044f \u0432 \u0444\u0430\u0439\u043b\u0435 info.cpp. \u0412 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u0444\u0430\u0439\u043b\u0430 info.cpp \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c info.h(\u043a\u0430\u0440\u043a\u0430\u0441 \u043a\u043b\u0430\u0441\u0441\u0430 info). \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 Info \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:  <\/p>\n<pre><code class=\"cpp\">Info::Info(QWidget *parent) :     QWidget(parent) {     hostname   = new QLabel(&quot;Hostname: &quot;);     user       = new QLabel(&quot;\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c: &quot;);     uptime     = new QLabel(&quot;Uptime: &quot;);     proc       = new QLabel(&quot;\u041f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440: &quot;);     freq       = new QLabel(&quot;\u0427\u0430\u0441\u0442\u043e\u0442\u0430:&quot;);     cpuload    = new QLabel(&quot;\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430: &quot;);     mem        = new QLabel(&quot;\u041e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c: &quot;);     memload    = new QLabel(&quot;\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c: &quot;);     cpubar     = new QProgressBar;     membar     = new QProgressBar;     layout     = new QVBoxLayout;     hlayout    = new QHBoxLayout;      cpubar-&gt;setMaximumHeight(21); membar-&gt;setMaximumHeight(21);     hlayout-&gt;addWidget(cpuload); hlayout-&gt;addWidget(cpubar);     layout-&gt;addWidget(hostname); layout-&gt;addWidget(user);     layout-&gt;addWidget(uptime); layout-&gt;addWidget(proc);     layout-&gt;addWidget(freq); layout-&gt;addLayout(hlayout);     layout-&gt;addWidget(mem); layout-&gt;addWidget(memload);     layout-&gt;addWidget(membar); setLayout(layout);      update();      QTimer *timer = new QTimer;     connect(timer, SIGNAL(timeout()), this, SLOT(update()));     timer-&gt;start(2000); } <\/code><\/pre>\n<p>  \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u043c\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435\u043c \u043c\u044b \u0440\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432 \u043b\u044d\u0439\u0430\u0443\u0442\u0430\u0445. \u041f\u043e\u0441\u043b\u0435 \u043c\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043b\u043e\u0442 update \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u043c\u0435\u0442\u043a\u0438 \u0438 \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u0431\u0430\u0440\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043b\u0438\u0441\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438. \u0427\u0442\u043e\u0431\u044b \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u043b\u0430\u0441\u044c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 QTimer, \u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0435\u0433\u043e \u0441\u0438\u0433\u043d\u0430\u043b timeout, \u0441 \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u043c \u043d\u0430\u043c \u0441\u043b\u043e\u0442\u043e\u043c update. <br \/>  \u0414\u0443\u043c\u0430\u044e \u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0441\u043b\u043e\u0442 update, \u0432\u043e\u0442 \u0435\u0433\u043e \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"cpp\">void Info::update() {     ifstream stream(&quot;\/proc\/sys\/kernel\/hostname&quot;); string str;     getline(stream,str);     hostname-&gt;setText(&quot;Hostname: &quot; + QString::fromStdString(str));     passwd *pw;     uid_t uid;     uid = geteuid();     pw = getpwuid(uid);     user-&gt;setText(&quot;\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c: &quot; + QString::fromAscii(pw-&gt;pw_name));     struct sysinfo o;     sysinfo(&#038;o);     long up = o.uptime;     int hour = up\/60\/60;     int min = (up - hour*60*60) \/ 60;     int sec =  ((up - hour*60*60) - min*60);     QString e = QString::number(hour) +  QString(&quot; h. &quot;) + QString::number(min) + QString(&quot; m. &quot;)                 + QString::number(sec) + QString(&quot; s.&quot;);     uptime-&gt;setText(&quot;Uptime: &quot; + e);     stream.close(); stream.open(&quot;\/proc\/cpuinfo&quot;);     stream &gt;&gt; str;     for(int i = 0; i &lt; 15;i++) stream &gt;&gt; str;     getline(stream,str);     proc-&gt;setText(&quot;\u041f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440: &quot; + QString::fromStdString(str));     for(int i = 0; i&lt; 7; i++)  stream &gt;&gt; str;     freq-&gt;setText(&quot;\u0427\u0430\u0441\u0442\u043e\u0442\u0430: &quot; + QString::fromStdString(str) + &quot; MHz&quot;);     cpubar-&gt;setValue(getCpuLoad(0.3));     stream.close(); stream.open(&quot;\/proc\/meminfo&quot;);     stream &gt;&gt; str; stream &gt;&gt; str;     int num = atoi(str.c_str());     int percent = num \/ 100;     int gb = (num \/ 1024) \/ 1024;     int mb = (num-gb*1024*1024) \/1024;     int kb = (num - (gb*1024*1024+mb*1024));     e = QString::number(gb) + QString(&quot; Gb &quot;) + QString::number(mb) + QString(&quot; Mb &quot;)         + QString::number(kb) + QString(&quot; Kb&quot;);     mem-&gt;setText(&quot;\u041e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c: &quot; + e);     stream &gt;&gt; str; stream &gt;&gt; str; stream &gt;&gt; str;     int free = atoi(str.c_str());     stream &gt;&gt; str; stream &gt;&gt; str; stream &gt;&gt; str;     free += atoi(str.c_str());     stream &gt;&gt; str; stream &gt;&gt; str; stream &gt;&gt; str;     free += atoi(str.c_str());     num -= free;     gb = num \/ 1024 \/ 1024;     mb = (num - gb*1024*1024) \/ 1024;     kb = (num - ((mb*1024) + (gb * 1024 * 1024)));     if (gb != 0 )     {         e = QString::number(gb) + &quot; Gb &quot; + QString::number(mb) + QString(&quot; Mb &quot;) + QString::number(kb)                + QString(&quot; Kb&quot;);     } else     {         e = QString::number(mb) + QString(&quot; Mb &quot;) + QString::number(kb) + QString(&quot; Kb&quot;);     }     memload-&gt;setText(&quot;\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c: &quot; + e);     percent = num \/ percent; membar-&gt;setValue(percent); } <\/code><\/pre>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f(\u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0430 \u0441\u0443\u043f\u0435\u0440\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f) \u0444\u0430\u0439\u043b \/proc\/sys\/kernel\/hostname \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043c\u044f \u043c\u0430\u0448\u0438\u043d\u044b, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043c\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043c\u0435\u0442\u043a\u0443 hostname. \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b passwd \u0438 uid_t, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043a\u0438 user. \u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0442\u043e\u043c \u043a\u0430\u043a \u0443\u0437\u043d\u0430\u0442\u044c \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0431\u044b\u043b\u0430 \u0432\u0437\u044f\u0442\u0430 \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b whoami. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b sysinfo, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0435\u0440\u0451\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u0430\u043f\u0442\u0430\u0439\u043c\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u0435. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u043c\u044b \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a stream \u0441 \u0444\u0430\u0439\u043b\u043e\u043c \/proc\/cpuinfo, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u0438\u043c\u0435\u043d\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0438 \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u043e\u0442\u0435. \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 getCpuLoad, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u043e\u043f\u0438\u0448\u0443 \u043d\u0438\u0436\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u0442\u043e\u043a stream \u0441 \u0444\u0430\u0439\u043b\u043e\u043c \/proc\/meminfo \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0431\u0435\u0440\u0451\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, \u0438 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c \u0435\u0433\u043e \u043a \u0443\u0434\u043e\u0431\u043d\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u043c\u0443 \u0432\u0438\u0434\u0443. \u041f\u043e\u0442\u043e\u043c \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0436\u0435 \u0444\u0430\u0439\u043b\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043e\u0431\u044a\u0451\u043c \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u043d\u044f\u0442\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043c\u044b \u0432\u044b\u0447\u0438\u0442\u0430\u0435\u043c \u0438\u0437 \u0432\u0441\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043a\u0443 \u0438 \u043e\u0431\u044a\u0451\u043c \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0441\u043b\u0435 \u043e\u043f\u044f\u0442\u044c \u0436\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c \u043a \u0443\u0434\u043e\u0431\u043d\u043e \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u043c\u0443 \u0432\u0438\u0434\u0443. \u0422\u0435\u043f\u0435\u0440\u044c \u043a\u0430\u043a \u044f \u043e\u0431\u0435\u0449\u0430\u043b \u0432\u044b\u0448\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 getCpuLoad. \u042d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u044f \u043f\u0438\u0441\u0430\u043b \u043d\u0435 \u0441\u0430\u043c(\u044f \u0435\u0451 \u0432\u0437\u044f\u043b \u0432\u043e\u0442 <a href=\"http:\/\/0xc0dec.org\/2011\/06\/16\/cpp_linux_cpu_load\/\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a>), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0433\u043e \u0435\u0451 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u044f \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043d\u0435 \u043c\u043e\u0433\u0443, \u044f \u043e\u043f\u0438\u0448\u0443 \u0435\u0451 \u0432 \u043e\u0431\u0449\u0438\u0445 \u0447\u0435\u0440\u0442\u0430\u0445. \u0412\u043e\u0442 \u043e\u043d\u0430:  <\/p>\n<pre><code class=\"cpp\">int Info::getCpuLoad(double dt) {     vector&lt;float&gt; stats1 = readCpuStats();     QProcess::execute(&quot;sleep&quot;,QStringList() &lt;&lt; QString::number(dt));     vector&lt;float&gt; stats2 = readCpuStats();     int size1 = stats1.size();     int size2 = stats2.size();     if (!size1 || !size2 || size1 != size2) return 2;     for (int i = 0; i &lt; size1; ++i) stats2[i] -= stats1[i];     int sum = 1;     for (int i = 0; i &lt; size1; ++i) sum += stats2[i];     int load = 100 - (stats2[size2 - 1] * 100 \/ sum);     return load; } <\/code><\/pre>\n<p>  \u043c\u044b \u0434\u0432\u0430 \u0440\u0430\u0437\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0440\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 readCpuStats(\u0435\u0451 \u044f \u0442\u043e\u0436\u0435 \u043e\u043f\u0438\u0448\u0443 \u043d\u0438\u0436\u0435), \u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u044b \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u043e\u043c \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u044d\u0442\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0410 \u0432\u043e\u0442 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 readCpuStats:  <\/p>\n<pre><code class=\"cpp\">vector&lt;float&gt; Info::readCpuStats() {     vector&lt;float&gt; ret;     ifstream stat_file(&quot;\/proc\/stat&quot;);     if (!stat_file.is_open())     {         cout &lt;&lt; &quot;Unable to open \/proc\/stat&quot; &lt;&lt; std::endl;         return ret;     }     int val;     string tmp;     stat_file &gt;&gt; tmp;     for (int i = 0; i &lt; 4; ++i)     {         stat_file &gt;&gt; val;         ret.push_back(val);     }     stat_file.close();     return ret; } <\/code><\/pre>\n<p>  \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u044b\u043b\u0430 \u0432\u0437\u044f\u0442\u0430 \u0441 \u0442\u043e\u0433\u043e \u0436\u0435 \u0441\u0430\u0439\u0442\u0430 \u0447\u0442\u043e \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f getCpuLoad. \u0412 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043c\u044b \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \/proc\/stat, \u0438 \u0437\u0430\u043d\u043e\u0441\u0438\u043c \u0438\u0445 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0442\u043e\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c return.<br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043b\u0430\u0441\u0441 Info \u043d\u0430\u043f\u0438\u0441\u0430\u043d, \u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430 ProcessTable. \u0412\u043e\u0442 \u043a\u0430\u0440\u043a\u0430\u0441 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430:  <\/p>\n<pre><code class=\"cpp\">#ifndef PROCESSTABLE_H #define PROCESSTABLE_H  #include &lt;QtGui&gt; #include &lt;iostream&gt; #include &lt;fstream&gt; using namespace std; class ProcessTable : public QWidget {     Q_OBJECT public:     explicit ProcessTable(QWidget *parent = 0); private:     QTableWidget * table;     QHBoxLayout* hlayout;     QPushButton* button;     QVBoxLayout* layout; public slots:     void update();     void kill(); };  #endif \/\/ PROCESSTABLE_H <\/code><\/pre>\n<p>  \u0421\u043b\u043e\u0442 update \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0430 \u0441\u043b\u043e\u0442 kill \u0434\u043b\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432. \u0412 \u0444\u0430\u0439\u043b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u0441 \u0435\u0433\u043e \u043a\u0430\u0440\u043a\u0430\u0441\u043e\u043c. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0436\u0443 \u043a \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0432\u043e\u0442 \u043a\u043e\u0434 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430:  <\/p>\n<pre><code class=\"cpp\">ProcessTable::ProcessTable(QWidget *parent) :     QWidget(parent) {     hlayout = new QHBoxLayout;     button = new QPushButton(&quot;\u0417\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c&quot;);     button-&gt;setToolTip(&quot;\u0414\u043b\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0432\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0435\u0433\u043e PID \u0438 \u043d\u0430\u0436\u0430\u0442\u044c \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \\&quot;\u0417\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c\\&quot;&quot;);     connect(button,SIGNAL(clicked()),this,SLOT(kill()));     hlayout-&gt;addStretch();     hlayout-&gt;addWidget(button);     layout = new QVBoxLayout;     table = new QTableWidget;     update();     layout-&gt;addWidget(table);     layout-&gt;addLayout(hlayout);     <\/code><\/pre>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-186944","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/186944","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=186944"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/186944\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=186944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=186944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=186944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}