Friday, May 30, 2025

Link count

The link count of a directory or file in Linux refer to the number directory reference table o the inode from all the directories in the inode table. This include .. in a child directory. 

The exception is for the root inode with an extra 1 link count because this is the superblovk pointer to the root inode 

Sunday, May 25, 2025

QR code

Quick response code is designed to be readable in high speed comparing to barcode. QR code has special position detection pattern at 3 comers so that the code can be read 360 degeee. Applications can detect the QR code 20 times faster than bar code. 

QR code position pattern at 3 corner allows it to be easily derived if its position, size and inclination. It also has timing pattern running from one position detection pattern to another,and alignment patterns as smaller square within the code grid. 

Friday, May 23, 2025

Schmitt trigger

Noise will be transferred to output when mapping through a transfer function because noise cause the signal to cross the threshold more than once. Transfer function is not symmetric such as the rising and falling of signal follow a different transfer functions. The difference between the 2 transfer function added buffer to the noise and thus increased noise resistance   Gate that include hysteresis was invented by Schmitt. The cost for Schmitt trigger gate is more expensive to produce because they are more complex. 

Vacuum tube

Vacuum tube has a cathode and an anode. When heat applies to the cathode, electrons become free to move and is collected at the anode. A grid placed between the cathode and anode and manipulating the grid turns vacccum tube into a switch

Electromechanical relay

A relay is a device that use electromagnet to move a switch. As magnetic is created by passing electricity through a wire coil, the magnetic force attract a level to either break or complete a circuit to give an output based on the design. 

Mechanical relay is slow, noisy and can wear out. A bug trapped in a rely give the term bug in computer. 

Transfer function

A transfer function is a graph that map values if input to output. The steepness of the function graph “amplify” the input and becomes the output. The transfer function in real world is not linear. The toe and shoulder of the graph are termed as cut off and distortion respectively. The steepness of the curve in the middle section is called gain. The design of the mechanism is to make sure the input stay in the stable (linear) middle portion of the graph. 

Friday, May 9, 2025

Bash spawn new bash

When executing a script, a child bash process (shell) is spawned. The child shell inherits the environment variables from the parent. The child shell sources $HOME/.bashrc for further customisation. 

Bash set up

Init runs multiple getty to listen on connection (console, network, modem). When a connection comes in, getty display the login prompt to get the userid entered. Getty spawns login program to display the password prompt. User enter password and login checks the credentials. Login then run the shell specified in etc/password for the user. 

The first hash shell is launched with login flag on. It execute the /etc/profile which set up the basic environment for everyone. Then it looks into $HOME and  execute one of .bash_profile, .bash_login and .profile to set up the personal environment. These files source $HOME/.bashrc. All these files set up environment variables. 

When the shell is logged out, ~/.bash_logout is sourced 

Thursday, May 8, 2025

Journal control

In the systemd framework, the process to manage logs is called systemd-journal. The benefit of using this is that it can merge all log into one place including kernel logs. Use command journalctl to display the log messages. 

Printk

Kernel cannot access the c lib for printf and has its own functionally equivalent version called printk. Printk writes to a ring buffer, a memory buffer that wrap around. Com and dmesg read and display the content in the ring buffer.  Redhat writes the messages in the ring buffer to /var/log/messages. 

The standard message for printk is to prefix a severity level (alias to a number) to aid filtering. The default (or if not specified) is 4 which equivalent to warning. 

A set of pr_* macros (eg pr_emerg) embeds the printk call make it more handy to emit kernel messages. Pr_debug willl emit the message only if Debug is defined or go nothing.