Codebase list dtkwidget / 08ed2df
Add OOM score adjust func Change-Id: Ic82837d98499f41b0701d6eba55ff9c000362b41 石博文 authored 6 years ago sbwtw committed 6 years ago
3 changed file(s) with 28 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
4040 a.loadTranslator();
4141 a.setAttribute(Qt::AA_EnableHighDpiScaling, true);
4242 a.setTheme("light");
43 #ifdef Q_OS_UNIX
44 a.setOOMScoreAdj(500);
45 #endif
4346
4447 if (!a.setSingleInstance("deepin-tool-kit-examples")) {
4548 qDebug() << "another instance is running!!";
336336
337337 d->setTheme(theme);
338338 }
339
340 #ifdef Q_OS_UNIX
341 /**
342 * @brief DApplication::setOOMScoreAdj set Out-Of-Memory score
343 * @param score vaild range is [-1000, 1000]
344 */
345 void DApplication::setOOMScoreAdj(const int score)
346 {
347 if (score > 1000 || score < -1000)
348 qWarning() << "OOM score adjustment value out of range: " << score;
349
350 QFile f("/proc/self/oom_score_adj");
351 if (!f.open(QIODevice::WriteOnly))
352 {
353 qWarning() << "OOM score adjust failed, open file error: " << f.errorString();
354 return;
355 }
356
357 f.write(std::to_string(score).c_str());
358 }
359 #endif
339360
340361 /**
341362 * @brief DApplication::setSingleInstance marks this application to be single instanced.
5454
5555 QString theme() const;
5656 void setTheme(const QString &theme);
57
58 #ifdef Q_OS_UNIX
59 void setOOMScoreAdj(const int score);
60 #endif
5761
5862 bool setSingleInstance(const QString &key);
5963