#include <iostream>
#include <csignal>
#include <ctime>
#include <cerrno>
#include <cstring>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
#include <stdio.h>
void timer_handler(int signo) {
struct timeval tv;
gettimeofday(&tv, NULL);
char buf[100];
struct tm* nowtm;
nowtm = localtime(&tv.tv_sec);
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", nowtm);
printf("Timer expired at %s.%03ld\n", buf, tv.tv_usec / 1000);
}
int main() {
timer_t timerid;
struct sigevent sev;
struct itimerspec its;
struct sigaction sa;
// Install the timer handler
sa.sa_flags = 0;
sa.sa_handler = timer_handler;
sigemptyset(&sa.sa_mask);
if (sigaction(SIGRTMIN, &sa, NULL) == -1) {
std::cerr << "sigaction: " << errno << std::endl;
return -1;
}
// Create the timer
sev.sigev_notify = SIGEV_SIGNAL;
sev.sigev_signo = SIGRTMIN;
if (timer_create(CLOCK_REALTIME, &sev, &timerid) == -1) {
std::cerr << "timer_create: " << errno << std::endl;
return -1;
}
// Set the timer to expire every second
its.it_value.tv_sec = 1;
its.it_value.tv_nsec = 0;
its.it_interval.tv_sec = 1;
its.it_interval.tv_nsec = 0;
if (timer_settime(timerid, 0, &its, NULL) == -1) {
std::cerr << "timer_settime: " << errno << std::endl;
return -1;
}
// Main loop
while (true) {
pause(); // Wait for signals
}
return 0;
}
Sunday, September 21, 2025
Qt console hello world
Qt console hello world
This guide shows how a Qt console hello world looks like.
▣ Open Qt Creator and click on Create Project...
▣ Create Qt Console Application by following the section from @1 to
@3.
▣ In Project Location window provide a project name, i.e.,
HelloWorldConsole▣ In Define Build System select CMake
▣ In Translation File, take the default values
▣ In Kit Selection, select the toolchain kit to be used. Below shows only one which is MinGW 64-bit.
▣ In Project Management, take the default.
▣ In line 6, I have added an instruction to output Hello World in to the console. Also changed to return 0 to exit the application as event loop is not needed.
▣ Gist source code shown below for convenience
In Qt Creator 17.0.1/Qt 6.9.2, need to add QTextStream
▣ Running it using Qt Creator is well and good but we probably want to run
it external to the IDE. To deploy the binary with all the dependencies, open
the compiler environment used to build the application. In the case above we
have used Qt 6.4.1 (MinGW 11.2.0 64-bit).
▣ Run the following command (change the paths as necessary)cd \ md tmp cd tmp copy C:\Users\t\Documents\build-HelloWorldConsole-Desktop_Qt_6_4_1_MinGW_64_bit-Debug\HelloWorldConsole.exe windeployqt HelloWorldConsole.exe
▣ The folder structure should look like this. It also shows a sample out
from the application.
Keywords: CPP, Qt, Hello World
Wednesday, September 17, 2025
Several modules must be compiled when running VMware Workstation on Ubuntu
Several modules must be compiled when running VMware Workstation on Ubuntu
I have a machine with Ubuntu 24.04.2 with VMware Workstation working as expected. When I connected to the machine Ubuntu told me there were packages available that can be updated inlcuding the kernel. So, I did the update and rebooted the machine. Running VMware Workstation failed with "several modules must be compiled". The fix is quite easy, run the following to fix it.$ sudo vmware-modconfig --console --install-all
Notes: - VMWare Workstation: 17.6.3
- Host: Ubuntu 24.04.2 LTS
Friday, September 12, 2025
Hello world assembly on x86 Linux
Hello world assembly on x86 Linux
Save code below as hello.asmglobal _start
section .data
message: db 'hello, world!', 10
section .text
_start:
mov rax, 1 ; system call number should be stored in rax
mov rdi, 1 ; argument #1 in rdi, where to write (description)?
mov rsi, message ; argument #2 in rsi, where does the string start?
mov rdx, 14 ; argument #3 in rdx, how many bytes to write?
syscall ; this instruction invokes a system call
mov rax, 60 ; 'exit' syscall number
xor rdi, rdi
syscall
Now assemble/build the file
nasm -felf64 hello.asm -o hello.o
Link to create executable
ld -o hello hello.o
Run it
u1@v1vm10:~$ ./hello
hello, world!
Wednesday, September 10, 2025
Formatting code in Blogger
I have been using Github gists to share code and I have no plan of
abandoning it. For smaller/one liners, I sometimes use div element with inline
CSS.
I have been exploring formatting my code directly in Blogger but it is mostly hit and miss. I came accross highlight.js and I am impressed with the result.
Below is a quick guide how to format code using highlight.js:
I have been exploring formatting my code directly in Blogger but it is mostly hit and miss. I came accross highlight.js and I am impressed with the result.
Below is a quick guide how to format code using highlight.js:
Sunday, September 07, 2025
Test page for code formatting
netsh advfirewall firewall add rule name="RPC Endpoint Mapper" dir=in action=allow protocol=TCP localport=135
netsh advfirewall firewall add rule name="RPC Endpoint Mapper" dir=in action=allow protocol=TCP localport=135
Tags: - Highlight.js
- hilite.me
Subscribe to:
Posts (Atom)