Sunday, August 17, 2025

Source command

The command "source" command or "." is to run a command in the current shell (process), instead of spawning a new child process to run it.

For example, 

. ./program1 runs program 1 in the current shell.  The same command can be typed as source .program1

./program1 runs program1 in a child shell.

file redirection

In Linux, redirecting input and output of command uses  ">" or "<" characters.  For example, 

cat file1 file2 file3 1> outfile 2>&1

redirects the output of cat command to a file called outfile and error message also go to the same outfile.  The numbers 1, 2 etc are actually file descriptors.

Shorthand for 2>&1 is |&

Default file descriptor for ">" is 1 so 1 can be omitted

Default file descriptor for "<" is 0 (standard input)

BASH

The initialization of bash is different when it is started from login event or started as a shell after login.

When user login, Linux starts a shell based on configuration in /etc/passwd specified by admin.  If it is a bash shell, the command in /etc/profile will firstly be applied, then followed by all the script suffixed with .sh in /etc/profile.d.  The latter allow maintaining local customization to /etc/profile which may be replaced during upgrade.  Then .bach

-profile, .bash_login or .profile file in the user's home directory is executed to allow personalization.  When user log off, .bash_logout file will run to clean up like temp files.

When bash is invoked not from login, it will not run those files above.  Instead, it runs .bashrc in the user's home directory to initialize.  .bashrc usually call /etc/bashrc.

When bash is invoked in non-interactive mode (e.g. execute a script), none of the start up files above will be run.  The shell will only inherit the environment variables from its parent shell.

SUN RPC

When a server (service) using rpc starts, it registers with rpcbind (portmapper) process. It can either bind to a port it selected itself and register, or let rpcbind allocates a port afterwhich the server will bind itself to. 

When a client need to use rpc server, it send request to rpcbind which will return the port used by the server sought. The rpc library in client and server will handle encoding the request into rpc format and decide. 

Rpc client identify a rpc server using a rpc number that coded in /etc/rpc. The port is mapped in /etc/servcies 

Sunday, August 10, 2025

MySQL architecture

There are 3 layers. 

The layer handles connection, authentication and security 

The second layer is the optimizer, execution engine and cache. 

The bottom layer is the storage engines. The storage engine API make it transparent to the query. Transaction is implemented in this layer. 

Friday, August 8, 2025

Database logging

Logging allows the changed data to be updated to the table at a later time. Although logging is achieved by writing the data out to log, it has better performance than writing the data out to table  the reason is logging is always appending at the end of the log file as compare to randomly seek to the spot when writing to the table. The io is also less 

Isolation mode

Read uncommitted aka dirty read allows reading data that have not been committed by transaction. 

Read committed allows only retrieving rows that has been committed. But a repeating read may return different result as there are committed changes in between successive read

Repeatable read allows the same result to return in successive read but it still allows phantom read. Rows that inserted between successive read. T only protected the rows read from changing. 

Serializaruon is to do one query at a time thus preventing all changes until the current transaction commits.