Where does UNIX come from?

Greetings to all 🙂 these weeks I have been quite entertained reading some books on programming, the truth is that the best way to learn to program is always with a book, any article, tutorial, guide that one can find (including mine) are mere benchmarks when comparing them to a real book on the subject. Now, we have to define what a "real" book is as well, since not all books are usually good, and many of them can even cost more than they are really worth and waste time.

Throughout these years the list of books that I have read and the list of books that I can recommend have diverged quite a bit, but without a doubt among some of my favorites we have (in no specific order):

  • CEH Certified Ethical Hacker by Matt Walker.
  • Beginning Python: From Novice to Professional by Magnus Lie Hetland.
  • Hacking: the art of exploitation by Jon Erickson.
  • Getting Started with Arduino by Massimo Banzi.
  • Learning the bash Shell by Cameron Newbam & Bill Rosenblatt.
  • Learning the vi and vim editors by Arnold Robbins, Elbert Hannah & Linda Lamb.
  • Linux Kernel in a Nutshell by Greg Kroah-Hartman (a Gentoo developer too).
  • Modern C by Jens Gustedt
  • The Shellcoder's Handbook by Chris Anley, John Heasman, Felix «FX» Linder & Gerardo Richarte.
  • The C programming language by Brian W. Kernighan & Dennis M. Ritchie (creators of C)
  • Debugging with GDB by Richard Stallman, Roland Pesch, Stan Shebs, et al.
  • Hacking Linux Exposed: Linux Security Secrets and Solutions from a large group of ISECOM researchers, including Pete Herzog, Marga Barceló, Rick Tucker, Andrea Barisani (another former Gentoo developer), Thomas Bader, Simon Biles, Colby Clark, Raoul Chiesa , Pablo Endres, Richard Feist, Andrea Ghirardini, Julian "HammerJammer" Ho, Marco Ivaldi, Dru Lavigne, Stephane Lo Presti, Christopher Low, Ty Miller, Armand Puccetti & et al.
  • Operating Systems: A Concept-Based Approach by Dhananjay M. Dhamdhere
  • Pro Git by Scott Chacon and Ben Straub
  • Expert C Programming: Deep secrets by Peter Van Der Linden.

I could speak highly of each of these books, but for today we will take some of the passages from the last one on the list, since many of these anectodes have captivated me and helped me better understand some of the intricate secrets of C and programming in general. 🙂

Unix and C

When we talk about UNIX, history is intertwined with the origin of this system and the development of the language that to this day is one of the most used in the development of it and its derivatives (including Linux). And curiously, these two are born from a "mistake."

multrics It was a mega project that brought together Bell laboratories, General Electric and MIT itself to create an operating system. This system presented many errors, and among one of the most important, performance failures that made the system practically unusable. We are talking about the year 1969, so the hardware of that time could not support the amount of software that was needed to run the system itself.

It wasn't until 1970 that a couple of Bell engineers began working on a simple, fast, and lightweight operating system for the PDP-7. The whole system had been written in Assembler and had been called UNIX as a parody of multrics since he only wanted to do a few things, but to do them well instead of the tremendous wasted work that the second meant. Now you can understand why Epoch begins January 1, 1970. 🙂 A rather curious fact for me. At that time, there was still no talk of a C itself, but of a New B since Ritchie's ideas came from the already used B language of that time.

Early C

Over the years (1972-3) the term C began to be used since the new language began to take shape, and around this time another curious fact is born, many programmers and programmer jokes say:

Programmers know that you start counting from 0 instead of 1.

Well, this is not entirely true 🙂 the real reason why this is considered this way to this day is because at its creation, for compiler writers it was easier to calculate an array using offset, these indicate the distance that exists from a point of origin to the desired objective, that is why:

array[8]=2;

It tells us that the element of array is defined as 2, because 8 units are added to the array to reach the memory space where element 2 will be stored. Before C, many languages ​​started counting from 1, thanks to C, now almost all start with 0 🙂 so it's not the programmers 'fault, but the compiler writers' fault that this is so.

The Bourne Shell

This is a topic that, although not directly related to C, can help more than one understand why Shell programming is so peculiar, and it is certainly curious to know. Steve Bourne wrote a compiler for Algol-68 that season, this is a language in which the keys ( {} ) are replaced by words, so we could define it as follows in C:

#define IF if(

#define THEN ){

#define ELSE }else{

#define FI };

These are just some examples of what Algol understands, but if we apply it to shell programming today, you will understand why in shell your programs require a fi for each if 🙂 certainly interesting.

Start reading

I can't tell you all the details of the book, especially since many of these are already programming topics that require a prior background to be understood, but I thought I would share with you some of the curious anecdotes that I found along the way 🙂 I have not had Time to work on some of the items that have been on the to-do list because these last few books have simply caught me and I'm enjoying them every day and above all trying to understand them to the fullest. Greetings and soon I will be able to share with you more topics, greetings.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Juan said

    Your article has been very interesting to me. Thanks a lot.

  2.   HO2Gi said

    Very interesting as always.

  3.   Jose Rafael said

    Very interesting the clarifications are good.

  4.   Alex said

    Excellent

  5.   danielga said

    Interesting !!! Thanks a lot.

  6.   second said

    multrics? it won't be multics (https://en.wikipedia.org/wiki/Multics)

    languages ​​with indexes from 1 are an invention of satan ...

    1.    ChrisADR said

      Interesting note 🙂 I suppose that at some point in history both terms have been used:

      https://www.landley.net/history/mirror/collate/unix.htm

      and obviously the same book that is written in the mid-90s.

      Thanks for the clarification 🙂 greetings

      1.    second said

        wa, what a strange thing, you have made me doubt, I have looked in a "purchased" copy of Expert C Programming: Deep secrets and there are multics coming, it is the first time I have heard that multrics. How curious, it reminds a little of the trix rabbit

        1.    ChrisADR said

          hahaha certainly curious, I checked my English copy of deep secrets, there it also says Multrics (because you had also made me doubt) ... maybe it was an expression of the time 😛

          regards

  7.   ED774 said

    Great contribution

  8.   Anonymous said

    Interesting, although surely, Multrics is due to a misprint, since the original name of that operating system was Multics, and Unix was originally called Unics, precisely referring to that great operating system, eventually and by phonetics, Unics se transformed into Unix, now, you only had to mention the name of the person who considers himself the author of Unix; Ken Thompson, legend has it that both Thompson and Ritchie were in the Bell Labs cafeteria commenting on their projects and it was that Ritchie suggested to Thomposon that he rewrite his Unics with C program, the language he had written ... and the rest , is history. 😉

    By the way, previously all programs were written with the instructions of the machine, which made them totally dependent on the hardware, the innovation of C, apart from making it easier to write programs, was that the language was independent of the hardware implementing the compilers, a philosophy that many years later Java would take, in the sense that the programs were not dependent on the operating system, adding the famous Java virtual machine.

    1.    ChrisADR said

      The bad thing about legends is that they distort history, in more ways than one ... and they can make you think that something happens when it is not ... like the fact of the existing conversation between Thompson and Ritchie (which I omitted at will) since it leads to historical and technical errors (C was not before UNIX) ...

      And as for the second ... another legend that distorts reality, since before C there were B, A, pascal, Ada, algol-60, PL / 1 and a few more that were properly programming languages ​​(very different from Assembly and their dialects by architecture that are dependent on the hardware of the processor) so C did not "innovate" in this sense, he simply adopted solutions that already existed in other languages ​​and in the end it became popular faster and better than these ... The only part The truth is that Java was based on this concept of portability to later create its virtual machine, but not only did it rely on C for this, but it followed other models, otherwise we would not have the object-oriented programming paradigm in java ...

      I felt that I should clarify the situation because anyone less well versed could take it as true and then believe that it happened like this ... greetings 🙂

  9.   Ignatius Esquivel said

    As always, the article is very interesting, thanks for the contribution.