Pages

Sunday, June 13, 2021

Fedora 34 : Linux tool to prevent OOM Killer.

The OOM Killer or Out of Memory Killer is a process that the Linux kernel employs when the system is critically low on memory
This situation occurs because processes on the server are consuming a large amount of memory, and the system requires more memory for its processes and to allocate to other processes.
A simple example with OOM Killer: if will swap out the desktop environment, drop the whole page cache, and empty every buffer before it will ultimately kill a process.
This tool named earlyoom is a simple, stable, and tiny OOM prevention daemon.
That is written in C and is the best choice for old servers.
It has minimum dependencies and can work with the oldest kernels.
The earlyoom checks the amount of available memory and free swap up.
This command causes memory consumption, and the process will exits before OOM occurs if this tool works.
The tool can be installed with the following command:
[root@desk mythcat]# dnf install earlyoom
Last metadata expiration check: 0:38:00 ago on Sun 13 Jun 2021 11:38:22 AM EEST.
Package earlyoom-1.6.2-3.fc34.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
You can see all options for this tool with this command:
[root@desk mythcat]# earlyoom -h
earlyoom 1.6.2
Usage: earlyoom [OPTION]...
Then the service is activated with:
[root@desk mythcat]# systemctl enable --now earlyoom
My configuration file for this tool is:
[root@desk mythcat]# vim  /etc/default/earlyoom
EARLYOOM_ARGS="-r 1 -m 1 -s 5 -M 1514244 --prefer '^Web Content$' 
--avoid '^(dnf|packagekitd|gnome-shell|gnome-session-c|gnome-session-b|lightdm|
sddm|sddm-helper|gdm|gdm-wayland-ses|gdm-session-wor|gdm-x-session|Xorg|Xwayland|
systemd|systemd-logind|dbus-daemon|dbus-broker|cinnamon|cinnamon-sessio|kwin_x11|
kwin_wayland|plasmashell|ksmserver|plasma_session|startplasma-way|xfce4-session|
mate-session|marco|lxqt-session|openbox|cryptsetup)$'"
You can check the status of the service to be active:
[root@desk mythcat]# systemctl status earlyoom
...
Active: active (running) since 
... 
You can test it easily with these commands:
[root@desk mythcat]# sudo swapoff -a
[root@desk mythcat]# tail /dev/zero
Terminated
The process tail must occupy the entire available RAM on the system, this will low your system and after the earlyoom tool freeing the RAM all works well.
To see the tool on work, use the command:
[root@desk mythcat]# earlyoom 
earlyoom 1.6.2
mem total: 7899 MiB, swap total: 7898 MiB
sending SIGTERM when mem <= 10.00% and swap <= 10.00%,
        SIGKILL when mem <=  5.00% and swap <=  5.00%
mem avail:  4742 of  7899 MiB (60.04%), swap free: 7898 of 7898 MiB (100.00%)
mem avail:  4742 of  7899 MiB (60.04%), swap free: 7898 of 7898 MiB (100.00%)
mem avail:  4751 of  7899 MiB (60.15%), swap free: 7898 of 7898 MiB (100.00%)
mem avail:  4754 of  7899 MiB (60.19%), swap free: 7898 of 7898 MiB (100.00%)

Thursday, June 10, 2021

Fedora 34 : Fix conflicts are between the version of the packages.

You can have conflicts are between the version of the packages, see this example:
[root@desk mythcat]# dnf update --refresh
file /usr/share/doc/gstreamer1-plugins-good/README from install of 
gstreamer1-plugins-good-1.19.1-1.fc34.i686 conflicts with file from package 
gstreamer1-plugins-good-1.18.4-2.fc34.x86_64
This command will fix conflicts are between the version of the packages:
[root@desk mythcat]# dnf remove --duplicates
...
 gstreamer1                          i686    1.19.1-1.fc34       updates  1.4 M
Reinstalling:
 gst-editing-services                x86_64  1.19.1-1.fc34       updates  608 k
     replacing  gst-editing-services.x86_64 1.18.4-1.fc34
 gstreamer1                          x86_64  1.19.1-1.fc34       updates  1.3 M
     replacing  gstreamer1.x86_64 1.18.4-2.fc34
 gstreamer1-plugins-bad-free         x86_64  1.19.1-1.fc34       updates  2.6 M
     replacing  gstreamer1-plugins-bad-free.x86_64 1.18.4-1.fc34
 gstreamer1-plugins-bad-free-extras  x86_64  1.19.1-1.fc34       updates  422 k
     replacing  gstreamer1-plugins-bad-free-extras.x86_64 1.18.4-1.fc34
 gstreamer1-plugins-ugly-free        x86_64  1.19.1-1.fc34       updates  103 k
     replacing  gstreamer1-plugins-ugly-free.x86_64 1.18.4-1.fc34
 gucharmap                           x86_64  13.0.8-1.fc34       updates  514 k
     replacing  gucharmap.x86_64 13.0.7-1.fc34
 gucharmap-libs                      x86_64  13.0.8-1.fc34       updates  1.2 M
     replacing  gucharmap-libs.x86_64 13.0.7-1.fc34
 kernel-headers                      x86_64  5.12.9-300.fc34     updates  1.2 M
     replacing  kernel-headers.x86_64 5.12.5-300.fc34
...
The next command will update you Linux distro:
[root@desk mythcat]# dnf update --refresh
Copr repo for dotnet owned by @dotnet-sig       5.1 kB/s | 3.3 kB     00:00    
Adobe Systems Incorporated                      7.6 kB/s | 2.9 kB     00:00    
Fedora 34 - x86_64                               58 kB/s |  26 kB     00:00    
Fedora 34 - x86_64 - Updates                     41 kB/s |  23 kB     00:00    
google-chrome                                   9.0 kB/s | 1.3 kB     00:00    
RPM Fusion for Fedora 34 - Free                  16 kB/s | 7.9 kB     00:00    
RPM Fusion for Fedora 34 - Free - Updates        18 kB/s | 7.9 kB     00:00    
RPM Fusion for Fedora 34 - Nonfree               21 kB/s | 8.0 kB     00:00    
RPM Fusion for Fedora 34 - Nonfree - Updates     13 kB/s | 8.0 kB     00:00    
The Zeek Network Security Monitor. (Fedora_33)  6.6 kB/s | 1.7 kB     00:00    
Visual Studio Code                              6.0 kB/s | 3.0 kB     00:00    
WineHQ packages                                 9.3 kB/s | 3.2 kB     00:00    
Dependencies resolved.
...
 gstreamer1-plugins-good-1.19.1-1.fc34.i686  
...

Wednesday, June 9, 2021

Fedora 34 : Programming with the ncurses library - part 003.

This is a simple example with ncurses library to see how can define an array and used with random colors:
This example is build with this command:
[mythcat@desk ncursesProject]$ gcc test_008.c -o test_008 -lncurses
This is source code:
#include <ncurses.h>
#include <stdlib.h> 

int main(void) {
    
    initscr();
    
    start_color();
    
    char colors[8][20] = {
    "COLOR_BLACK",
    "COLOR_RED",
    "COLOR_GREEN",
    "COLOR_YELLOW",
    "COLOR_BLUE",
    "COLOR_MAGENTA",
    "COLOR_CYAN",
    "COLOR_WHITE"
    };
    
    int n;
    for ( n=0 ; n<16 ; ++n )
    {
        int aleator1 = rand() % 256 + 1;
        int result1 = *colors[aleator1];
        int aleator2 = rand() % 256 + 1;
        int result2 = *colors[aleator2];
        //printw("%d",result1);
        init_pair(n, result1, result2);
        attron(COLOR_PAIR(n));
        printw("Hello word!\n");
    }
    
    refresh();

    getch();

    endwin();
}

Saturday, June 5, 2021

Fedora 34 : Neix feed reader.

neix is a simple, work in progress terminal feed reader for all common RSS/Atom feeds on the web out there.
Let't install from the GitHub repository.
[mythcat@desk ~]$ git clone https://github.com/tomschwarz/neix.git  
Cloning into 'neix'...
remote: Enumerating objects: 2574, done.
remote: Counting objects: 100% (365/365), done.
remote: Compressing objects: 100% (274/274), done.
remote: Total 2574 (delta 189), reused 198 (delta 77), pack-reused 2209
Receiving objects: 100% (2574/2574), 26.07 MiB | 6.27 MiB/s, done.
Resolving deltas: 100% (1529/1529), done.
[mythcat@desk ~]$ cd neix
[mythcat@desk neix]$ cmake .
-- The C compiler identification is GNU 11.1.1
-- The CXX compiler identification is GNU 11.1.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
...
-- Found Curses: /usr/lib64/libncursesw.so  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mythcat/neix
[mythcat@desk neix]$ make 
Scanning dependencies of target neixParser
[  5%] Building CXX object CMakeFiles/neixParser.dir/src/parser/FactoryParser.cpp.o
...
[ 89%] Built target neixFeed
Scanning dependencies of target neix
[ 94%] Building CXX object CMakeFiles/neix.dir/src/main.cpp.o
[100%] Linking CXX executable bin/neix
[100%] Built target neix
[mythcat@desk neix]$ sudo make install
[sudo] password for mythcat: 
[ 26%] Built target neixParser
[ 42%] Built target neixConfig
[ 57%] Built target neixApplication
[ 73%] Built target neixHelper
[ 89%] Built target neixFeed
[100%] Built target neix
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/bin/neix
-- Installing: /usr/local/share/man/man1/neix.1
-- Installing: /usr/local/share/neix/neix.conf
-- Installing: /usr/local/share/neix/feeds.conf
Let's run it:
[mythcat@desk neix]$ neix 
[neix] Starting version v0.1.5
[neix] Loading configuration files
[neix] Loading feeds 
[neix] Launch TUI 
Use feeds.conf to set the list of feeds you want to read.
This is a screenshot with the result of the build:

Saturday, May 29, 2021

Fedora 34 : Upgrade to the last version Fedora 34 Linux distro.

Today I upgraded from the fedora 33 version to the new Fedora 34 Linux distro version.
Here are the commands I used to upgrade this Linux distro:
[root@desk mythcat]# dnf upgrade 
[root@desk mythcat]# dnf --refresh upgrade
[root@desk mythcat]# dnf system-upgrade reboot
The whole process will require a restart and then continue with the following commands:
[root@desk mythcat]# dnf install dnf-plugin-system-upgrade --best
[root@desk mythcat]# dnf system-upgrade download --refresh --releasever=34 --allowerasing --skip-broken
[root@desk mythcat]# dnf system-upgrade reboot
[root@desk mythcat]# rpm --rebuilddb
[root@desk mythcat]# dnf distro-sync --setopt=deltarpm=0
[root@desk mythcat]# dnf install rpmconf
[root@desk mythcat]# rpmconf -a
[root@desk mythcat]# reboot
You can find this version on the official webpage.

Tuesday, May 25, 2021

Fedora 33 : Programming with the ncurses library - part 002.

Another example with this library, see the screenshot:

#include <ncurses.h&gt 

WINDOW *win;
int startx, starty, width, height;
int cport;


WINDOW *makewin(int h, int w, int y, int x)
{
    WINDOW *lwin;

    lwin = newwin(h, w, y, x);
    box(lwin, 0 , 0);
    wrefresh(lwin);

    return lwin;
}

void dewin(WINDOW *lwin)
{
    wborder(lwin, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
    wrefresh(lwin);
    delwin(lwin);
}

void getInput(){
    win = makewin(height, width, starty, startx);
    wbkgd(win, COLOR_PAIR(1));
    mvwprintw(win, 0, 8, "Question 1 : ");
    mvwprintw(win, 2, 4, "What is your age?");
    mvwprintw(win, 3, 4, "dd/mm/yy:");
    wrefresh(win);
    wscanw(win, "%d", &cport);
}

int main()
{
    initscr();
    cbreak();
    keypad(stdscr, TRUE);
    start_color();
    init_pair(1,COLOR_WHITE, COLOR_BLACK);
    init_pair(2,COLOR_WHITE, COLOR_BLUE);
    bkgd(COLOR_PAIR(2));
    refresh();
    
    height = 6;
    width = 30;
    starty = (LINES - height) / 2;
    startx = (COLS - width) / 2;
    
    getInput();
    getch();

    dewin(win);
    endwin();
    return 0;
}

Sunday, May 23, 2021

Fedora 33 : Programming with the ncurses library - part 001.

I started learning C and C ++ many years ago. Around 2004, the virtualization and S.D.K. class system for the Windows operating system confused me and was not to my advantage. Later I realized that it is more advantageous and faster to create your own tools with other programming languages. It turned out that I'm right and today I'm going to show you how simple it is to use C programming on the Linux Fedora 33 distro.
This library is easy to install on the Fedora Linux distro:
[root@desk mythcat]# dnf install ncurses-devel
Last metadata expiration check: 2:33:29 ago on Sun 23 May 2021 07:15:17 PM EEST.
Package ncurses-devel-6.2-3.20200222.fc33.x86_64 is already installed.
Package ncurses-devel-6.2-3.20200222.fc33.i686 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
I created a folder and with the vim editor, I created my file called test_001.c for the first test.
[mythcat@desk ~]$ mkdir ncursesProject
[mythcat@desk ~]$ cd ncursesProject/
[mythcat@desk ncursesProject]$ vim test_001.c
This is the content to initiate and display a simple text with this library:
#include <ncurses.h>
 
int main(void){ 
        initscr();                      /* start curses mode */
        printw("Hello World !");        /* print Hello World */
        refresh();                      /* send to the real screen */
        getch();                        /* wait for user input */
        endwin();                       /* end curses mode */
        return 0;
} 
I used cc and gcc commands for C compilers to test this example and it works great:
[mythcat@desk ncursesProject]$ cc -o test_001 test_001.c -lncurses
[mythcat@desk ncursesProject]$ ls -l
total 32
-rwxr-xr-x 1 mythcat mythcat 25312 May 23 22:14 test_001
-rw-r--r-- 1 mythcat mythcat   386 May 23 22:14 test_001.c
[mythcat@desk ncursesProject]$ ./test_001 
[mythcat@desk ncursesProject]$ gcc -o test_001_gcc test_001.c -lncurses
[mythcat@desk ncursesProject]$ ./test_001_gcc 
#include <ncurses.h>

int main() { 
    // create the pointer to the window
    WINDOW *w;
    // define the data
    char list[4][8] = { "","Festila", "George", "Catalin"};
    char item[8];
    int ch, i = 0, width = 8;
    initscr(); // initialize Ncurses
    // create the new window with ncurses
    w = newwin( 6, 11, 0, 0 ); 
    box( w, 0, 0 ); // sets default borders for the window
    // now print all the menu items and highlight the first one
    for(i=0; i<4; i++) 
        {
        if( i != 0 ) 
            // highlights the first item.
            wattron( w, A_STANDOUT ); 
        else
            // highlights the next item.
            wattroff( w, A_STANDOUT );
            sprintf(item, "%-8s",  list[i]);
            mvwprintw( w, i+1, 2, "%s", item );
            //wrefresh( w );
        }
        wrefresh( w ); // update the terminal screen
        i = 0;
        noecho(); // disable echoing of characters on the screen
        keypad( w, TRUE ); // enable keyboard input for the window.
        curs_set(0); // hide the default screen cursor.
        
    // get the input if is not q key presed then run
    while(( ch = wgetch(w)) != 'q')
    { 
        // right pad with spaces to make the items appear with even width.
        sprintf(item, "%-8s",  list[i]); 
        mvwprintw( w, i+1, 2, "%s", item ); 

        // use a variable to increment or decrement the value based on the input.
        switch( ch ) 
        {
            case KEY_UP:
            i--; // increment 
            // stop the number of count list items -1
            i = ( i<0 ) ? 3 : i;
            break;
            case KEY_DOWN:
            i++; // increment
            // stop the number of count list items 
            i = ( i>2 ) ? 3 : i;
            break;
        }
    
        // now highlight the next item in the list.
        wattron( w, A_STANDOUT );
        sprintf(item, "%-8s",  list[i]);
        mvwprintw( w, i+1, 2, "%s", item);
        wattroff( w, A_STANDOUT );
    }
    // delete window
    delwin( w );
    // stop the window
    endwin();
}
This is the result: