miércoles, 18 de septiembre de 2019

What happens when you type gcc main.c

What happens when you type gcc main.c


Resultado de imagen para compilation process

The answer is simple! When we run the main.c program gets processed by pre-processor. But what this means? We have to get inside the brain of a computer to understand the source of the preprocessor.

The brain of a computer only understand one language (the machine code) so through the compilation process the computer can compile several source files into a single program.


First (Preprocessing): This step removes all the comments from our program main.c. This process fixes the source, once it’s done, the source code will be ready for the actual compilation. 





The second step (Compilation): In this process, the output of the preprocessor is passed into the compiler and the compiler generates assembly code. The brain of the machine will start to add different components onto the stack. Assembly language describes the individual instructions the central processor will have to follow when running the program. 





Step 3 (Assembly): Since our computers cannot interpret assembly code, the job of the assembler is to convert assembly code into binary code (base2-Binary) since that is what the computer’s metal can actually read and write to.





The final step (Linking: put it all together): The linker accepts the "main" file at the beginning as input and once it has all of the separate pieces of object code, you need to fit them together like jigsaw pieces to form the executable program. 




The images and part of the Theoretical information were extracted from "Head First C by David Griffiths. Dawn Griffiths

lunes, 16 de septiembre de 2019

Hard Link and Symbolic Link

What is the difference between a hard link and a symbolic link? 


In Unix-like operating systems such as Linux, “everything is a file” and a file is fundamentally a link to an inode (a data structure that stores everything about a file apart from its name and actual content).
A hard link is a file that points to the same underlying inode, as another file. In case you delete one file, it removes one link to the underlying inode. Whereas a symbolic link (also known as soft link) is a link to another filename in the filesystem.
Another important difference between the two types of links is that hard links can only work within the same filesystem while symbolic links can go across different filesystems.
 Resultado de imagen para pc  +hard links
Looking at the output above, using ls command, the new file is not indicated as a link, it is shown as a regular file. This implies that tp is just another regular executable file that points to the same underlying inode as topprocs.sh.
To make a hard link directly into a soft link, use the -P flag like this. To create a hard links in Linux, we will use ln utility. For example, the following command creates a hard link named tp to the file topprocs.sh.

What happens when you type gcc main.c

What happens when you type gcc main.c The answer is simple!  When we run  the   main.c   program gets processed by   pre-processor ....