# Interview introspection 1 ###### tags: `interview` I have been interviewed recently and was asked many technical questions. One of question is pretty interest to me and I tried to answer all I know, I understand, I think it is and what I still remember. The question is, in linux system, what happen when you type command 'ls -l *.txt' and press enter. I know to answer this question, it could go very deeper and wide because it involves many system components and operation system concept to work together. So I would like to do a bit study to this question which also help me recall things I forgot and I do not know. And, I will begin write this as a series to record knowledgeable questions. #### bash When command string is passed to "bash" shell, shell identify it to command and its argument. The command could be an alias to another command and argument string. it will be replaced to the "actual" string if it matches to an alias. If command is not bash builtin, it searches for the command executable base on defined environment variable "PATH". If the executable could be found, then it fork a child process to execute it. The argument part is converted or expand to be passed to the command. such as "~" sign refer to current user home director path, '*.txt' matches all file name end with .txt in current directory base on regular expression syntax. #### kernel Kernel is involved all the time in this execution, include fork child process, search executable and system wide operation such as memory allocation and thread scheduling. For example to find executable in defined paths, it calls file system associated system call to get directory data from inode. To fork an process, memory relates operation is also involved to duplicate existing process stack. An unique PID is assigned to the child process and update process table in memory. #### file system The file system presents file structure to store and manage data file for operation system. Execution a binary executable stored on file system requires read and store it in memory. To read data on file system, many things are involved too. To access a file system, operation system needs to identify which storage device and check whether its mounted in virtual file system or not. File system has ACL which control accessibility to directory or file. The operation system retrieve the ACL to evaluate permission to current user. The "ls" command is used to read directory content which is list of file or sub-directory. Those data are stored from directory inode. The inode is an data structure to store data block information. Each file or directory has an inode associate with in file system. #### termination When child process terminates, it calls exit() system function. This will free up resources used by the process. It tells kernel that how it terminate by passing a termination status. Normally return status 0 means process terminated normal and successfully. #### other check allowed maximum number of arguments ``` $ getconf ARG_MAX 2097152 ``` check file inode ``` $ ls -i /var/log/journal/ 789037 0d70f43ab3474a2299f0c91992b9dbb8 786671 system.journal 789137 user-1000.journal ``` #### reference https://www.makeuseof.com/what-happens-when-you-run-command-linux/ https://linuxjourney.com/lesson/process-termination https://www.computerhope.com/unix/bash/index.htm http://ftp.gnu.org/pub/gnu/coreutils/ http://www.gnu.org/software/coreutils/ https://github.com/coreutils/coreutils/tree/master/src https://www.gnu.org/software/bash/manual/bash.html