QT set background image example(QLable_setstylesheet, QPixmap)

QT set background image example(QLable_setstylesheet, QPixmap)
I had a problem about applying image.

This is problem :
My app is working on an embedded system. I have migrated the app from Qt 5.6 to Qt 5.9.3 and it became very slow. I have checked the output of the top command and realized that my app is causing a CPU utilization of 100%.
So, I have check my app and I have found a problem in this part of the code:
MainWidget::MainWidget(QWidget *parent)
    : QWidget(parent)
{
...

    QPixmap bg(BACK_IMG_PATH);
    bg.fill(Qt::transparent);
    QPalette p(palette());
    p.setBrush(QPalette::Background, bg);
    setAutoFillBackground(true);
    setPalette(p);
...
}
The problem is, that if I add the code for the background, my app becomes extremely slow. However, if I remove this code, my app is working as expected. This cannot be a solution though, cause I need the background.
This problem did not exist before the migration.
I have tried to solve this by reimplementing the paintEvent and using QPainter like this:
void MainWidget::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.drawImage(QRectF(this->x(), this->y(), this->width(), this->height()), QImage("img/bg_1280_720.png"));
}
This result is slightly faster, but still not satisfactory (the cpu utilization is 50%).


How to solve this problem?

before:
#define BACK_IMG_PATH           "/img/bg_1280_720.png"
    QPixmap bg(BACK_IMG_PATH);
    bg.fill(Qt::transparent);
    QPalette p(palette());
    p.setBrush(QPalette::Background, bg);
    setAutoFillBackground(true);
    setPalette(p);


after:

#define BACK_IMG_PATH           "background-image:url(/img/bg_1280_720.png)"
    QLabel *labelBg = new QLabel(this);
    labelBg->setStyleSheet(BACK_IMG_PATH);
    labelBg->setGeometry(this->geometry());


Java Lotto / get random number example

This code was made in five minutes, so there are many weak point.

this code save that the number from 1 to 45 has been count N times.
finally, i will get 6 numbers.

import java.util.Random;

public class lottonamatja {
   public static void main(String[] args) {
      Random ranNum = new Random();    // random variable
      long[] cloneNum = new long[45]; 
      long[] num = new long[45];
      long[] lottoNum = new long[6];    // get real number(I wanted)
      long count = 1;
      long N = 100000000;
   
      for (long i = 0; i< N ; i++) {
         int tempRanNum = ranNum.nextInt(45)+1;    // random number of 1~45
         num[tempRanNum-1] += count;    // count of each number about N times
      }

//copy number
      cloneNum = num.clone();

// sorting count
      for (int i = 0; i < 45; i++) {
         for (int j = i + 1; j < 45; j++) {
            if (num[i] > num[j]) {
               long tmp = 0;
               tmp = num[i];
               num[i] = num[j];
               num[j] = tmp;
            }
         }
      }
   
// compare sorting number to original number ( this is real number(1~45), num[i] or cloneNum[j] is counting number)
      for (int i = 0 ; i < 6; i++) {
         for (int j = 0 ; j < 45; j++) {
            if (num[i] == cloneNum[j])
               lottoNum[i] = j+1;    // save result number 
         }
      }
   
// sorting about 6 number
      for (int i = 0; i < 6; i++) {
         for (int j = i + 1; j < 6; j++) {
            if (lottoNum[i] > lottoNum[j]) {
               long tmp = 0;
               tmp = lottoNum[i];
               lottoNum[i] = lottoNum[j];
               lottoNum[j] = tmp;
            }
         }
         System.out.print(lottoNum[i] + " ");    //i wanted to real number
      }
   }
}

RSS(Resident Set Size), VSS(Virtual Set Size)


RSS(Resident Set Size): Number of physical pages associated with the process(the size is calculated with duplicated shared memoy size, so, is calculated lager than the actual size)

VSS(Virtual Set Size): Size of virtual memory associated with the process


But, the amount of memory about the process is unknown exactly.


Why is the CPU utilization(%) for each process greater than the total CPU Time about "top"?


Why is the CPU utilization(%) for each process greater than the total CPU Time about "top"?

Two modes of "top" : solaris(irix mode off), irix(irix mode on)

Solaris mode: total cpu utilization(%) / total cpu count(number of core)
Irix mode: each cpu utilization(%) * total cpu count(number of core)

SMP(symmetric multiprocessing)

SMP(symmetric multiprocessing, 대칭형 다중 처리)

대칭형 다중 처리(symmetric multiprocessing, SMP)는 두 개 또는 그 이상의 프로세서가 한 개의 공유된 메모리를 사용하는 다중 프로세서 컴퓨터 아키텍처이다. 현재 사용되는 대부분의 다중 프로세서 시스템은 SMP 아키텍처를 따르고 있다.

SMP 시스템은, 작업을 위한 데이터가 메모리의 어느 위치에 있는지 상관없이 작업할 수 있도록 프로세서에게 허용한다. 운영체제의 지원이 있다면, SMP 시스템은 부하의 효율적 분배를 위해 프로세서간 작업 스케줄링을 쉽게 조절할 수 있다. 그러나 메모리는 프로세서보다 느리다. 단일 프로세서라도 메모리로부터 읽는 작업에 상당한 시간을 소비한다. SMP는 이를 더욱 악화시키는데, 한 번에 한 개의 프로세서만이 동일한 메모리에 접근 가능하기 때문이다. 이는 다른 프로세서들을 대기하도록 만든다.

SMP는 운영체제와 메모리를 공유하는 여러 프로세서가 프로그램을 수행하는 것을 말한다. SMP에서는 프로세서가 메모리와 입출력 버스 및 데이터 경로를 공유하며, 또한 하나의 운영체제가 모든 프로세서를 관리한다. 보통 2개부터 32개의 프로세서로 이루어지며, 어떤 시스템은 64개까지 프로세서를 공유한다. SMP 시스템은 보통 MPP 시스템에 비하여 병렬 프로그래밍이 훨씬 쉽고, 프로세서간 작업 분산(workload balance)을 시키기가 훨씬 용이하지만, 확장성은 MPP에 비하여 취약하다. 또한 많은 사용자가 동시에 데이터베이스에 접근하여 일을 처리하는 OLTP 작업에서도 강점을 보인다.

출처: https://ko.wikipedia.org/wiki/%EB%8C%80%EC%B9%AD%ED%98%95_%EB%8B%A4%EC%A4%91_%EC%B2%98%EB%A6%AC


Symmetric multiprocessing (SMP) involves a multiprocessor computer hardware and software architecture where two or more identical processors are connected to a single, shared main memory, have full access to all input and output devices, and are controlled by a single operating system instance that treats all processors equally, reserving none for special purposes. Most multiprocessor systems today use an SMP architecture. In the case of multi-core processors, the SMP architecture applies to the cores, treating them as separate processors.

Professor John D. Kubiatowicz considers traditionally SMP systems to contain processors without caches.[1] Culler and Pal-Singh in their 1998 book "Parallel Computer Architecture: A Hardware/Software Approach" mention: "The term SMP is widely used but causes a bit of confusion. [...] The more precise description of what is intended by SMP is a shared memory multiprocessor where the cost of accessing a memory location is the same for all processors; that is, it has uniform access costs when the access actually is to memory. If the location is cached, the access will be faster. but cache access times and memory access times are the same on all processors."[2]

SMP systems are tightly coupled multiprocessor systems with a pool of homogeneous processors running independently of each other. Each processor, executing different programs and working on different sets of data, has the capability of sharing common resources (memory, I/O device, interrupt system and so on) that are connected using a system bus or a crossbar.

출처: https://en.wikipedia.org/wiki/Symmetric_multiprocessing

linux reboot f option (forced reboot)


Reboot  option
"-f" option ( $ reboot -f )
It is unsafe and does not recommend.
The system will be forced shutdown.(like turning off the power button)

unsafe / not recommend
The process is power off without performing a normal shutdown.
If the critical processing is done in the shutdown process, it can cause problems in the system.

Apartment Buying Guide 2025: Shocking Red Flags You Should NEVER Ignore!

 🏙️ Apartment Buying Guide 2025: Shocking Red Flags You Should NEVER Ignore! 🚨 Are you thinking about buying an apartment in 2025? 🏢  It’...