The difference between LINUX and WINDOWS kernels

  

There are a lot of slobber stations about LINUX and WINDOWS. This paper attempts to compare the similarities and differences between the two mainstream operating systems
from a technical perspective. Focus on the kernel part.

I. Motivation:

I was the first WINDOWS camp. I have written more than 2 years of drivers under WINDOWS. Later, due to the need of learning, I switched to LINUX, and it was almost 2 years. During the period, I experienced a lot of twists and turns and learned a lot. Since the experience and knowledge are not enough when developing the WINDOWS driver, I feel more familiar with LINUX now.

Of course, every two years of study can only be said to be in the door. Every operating system is very powerful and constantly developing. Therefore, I just compare it from a personal point of view. It is inevitable that there are deficiencies. Welcome everyone to correct me.

I am writing this article and hope to help those who have also transferred from the WINDOW camp. I also hope that those who are interested in moving from LINUX to WINDOWS (such as the boss) and those who are interested in both will have some help.

Overall, I think the two operating systems have their own strengths. I like the freedom and openness of LINUX, and I like the uniformity and compatibility of WINDOWS. The following will compare the similarities and differences between the next two operating systems.

BTW: Regarding the version of the operating system, the WINDOWS kernel has not changed much since WIN 2K. I am also familiar with WIN2K, WIN XP. The LINUX kernel in the article is 2.6. Or more specifically, it is 2.6.18. Because I am most familiar with this version. However, the latest one seems to have been 2.6.31. In addition, regarding 2.6.18, a quote from this version of T-Bagwell students: “2.6.18 seems to be a relatively stable large version, just like 2.4.18, relatively stable, many companies, embedded are adopted” . The CENTOS 5 I use is based on 2.6.18.

Second, the difference between the two:

I think the biggest difference between the two is that WINDOWS is a commercial software, and LINUX is open source software. The advantage of commercial software is that it can concentrate a lot of manpower and material resources to do one thing. Easy to unify and compatible (because of customer needs). The benefits of open source are flexible and open.

In the following comparison, I generally introduce WINDOWS first, then introduce LINUX.

1, concept: business VS open source

WINDOWS is a commercial software, its source code is confidential. Of course, other non-MS people still have the opportunity to see the source code. If you and MS signs an NDA (NON DISCLOSURE AGREEMENT), then you may also get the WINDOWS code.

However, for the majority of poor students, and even VISUAL STUDIO are using pirated Tuen Mun companies, sign an NDA with MS It is almost unimaginable. So in the WINDOWS world, it is very difficult to understand the specific information of the WINDOW kernel. It can only be leaked by DDK (DRIVER DEVELOPMENT KIT) and WINDBG (kernel debugging tool). Then it is REVERSE ENGINEERING (reverse) Engineering, which can be simply understood as disassembly, is actually more complicated.)

This also caused the reason why the <WINDOWS INTERNALS> book is super hot. Because it is authorized by Microsoft, and it has been published a lot. Internal details. Another book on the kernel is <UNDOCUMENTED WINDOWS 2K SECRETS>, although old, but a lot of insider. About WINDOWS, undocumented and secrets These two words are definitely analogous to the words "Super Beauty". Because these things are usually not visible.

Correspondingly, in the Linux world, a common word is RTFS. That is READ THE FXXXXXX SOURCE CODE (this sentence is said to be the earliest linus torvalds, the father of LINUX). Meaning means "to read the damn code". The meaning of the words, I will give you the code, you still want to swear? It's like a man telling him GF /LP /LD, I have given you all the bank account passwords, you still want to swear?

In fact, he does not know (or does not know) that women still need your time and energy to accompany her. It is as if the LINUX programmer is not aware of the documentation. Of course, LINUX programmers should also know the importance of the documentation, but one is that the maintenance cost is too high, and the LINUX kernel changes too fast. So the documentation of LINUX always feels worse than MSDN.

When the WIN 2K source code leaked out, I couldn't wait to download it. Although I haven't seen it yet, the feeling of getting the WINDOWS source code is definitely no worse than a peerless beauty. (Of course, I really want to marry my wife or look inside.)

In contrast, LINUX is open source, the code is always visible. This is very shocking to me just transferred from the WINDOWS world. Although I have been Everyone knows this fact, but when you find out that you have to use all kinds of methods before, you can get all the information in a few words and now you are fully present in front of you, you can truly understand that open source is indeed a great project.

After reading the Linux source code, I finally found out that most of the original kernel is also C language (instead of the previously imagined assembly). At the same time, the kernel seems to be like that, not as mysterious as I thought before. The kernel is slightly more troublesome than compiling a normal program, and it takes a long time. The original compiled kernel can be used with a normal C compiler. The original kernel is also a normal executable file. (PS: I suspect MS is also using VS. Translation of WINDOWS. At the same time I also know that the WINDOWS kernel is also an executable file.) The original replacement of the kernel is so simple.

Finally, the kernel can be changed by me. Wow hahaha!

Follow the rules, I think business is still good. For example, compatibility is good. I used to write a driver with WDM. I can run it under WIN 98, WIN 2K, WIN XP at most. Very convenient. And if you switch to LINUX, then you have to pray that the different kernel versions do not change the header files and function interfaces that you use. Otherwise, you have to change the code.

At the same time, the benefits of open source are suitable for learning and very flexible. I think LINUX is very suitable for schools, students. Because of open source, when you find something you don't understand, you can go directly to the source (remember RTFS?). If you don't understand, you can ask at the forum. For WINDOWS, you want to understand its internal mechanism, you have to GOOGLE, and then pray. One of the better resources is a magazine under MSDN, which has a theme called UNDER THE HOOD, or Soso BUGSLAYER. The authors of these two topics, Matt Pietrek and John Robbins, are big-ticket characters.

By the way, the name UNDER THE HOOD itself. I have never understood it before, because the word HOOD means a cover. So what's the flaw under the cover? Why do you want to look under the cover?

After coming to the United States, I gradually understood. HOOD should be understood here as the hood of a car. In the United States, cars are very common. If you drive, but never open the hood, then you will only use it, not the interior of the car. So what if you open the lid to see it? You can see a lot of internal details, such as the engine smashing.

In the car kingdom of the United States, many software terms are related to cars, because people know cars well in their daily lives. For example, the word "engine", when playing 3D games, I often see the introduction, the game uses the latest 3D engine. What do you mean? The core part of the game (the car engine) has been upgraded. It’s not just to change the image of the outside person.

In addition, open source software is often analogized with cars. After the open source accident, you bought a car (software), you can get a repair shop to repair. That is, anyone can change, as long as he understands. The COPY RIGHT software is that you bought the car, but the engine cover is locked. If it is broken, it can only be repaired by the manufacturer. Other people can't fix it. If the manufacturer does not want to repair or repair it? Then you can only accept your life.

It’s a little farther, stop it.

1.1, release: binary VS source code

The main discussion here is the different forms and concepts adopted by WINDOWS and LINUX in the release program. These and the basic concepts of the previous business or open source are Linked together.

In the WINDOWS world, almost all installers are released in binary form. In other words, the user downloads a program, and then double-clicks, all the way NEXT, NEXT, NEXT will be fine. This method is very suitable for beginners. There are similar mechanisms in the Linux world, such as YUM, APT-GET, etc. However, YUM and APT-GET are relatively late, and before that, it was more troublesome to install the program in the Linux world.

Sometimes, LINUX YUM, APT-GET is not enough. For example, some people write a small software that is not placed in these large public libraries. At this time, you will find that they generally provide one or a bunch of source files, and then users need to download them themselves, & nbsp; compile & rdquo;, install. This is also the form of source code release that is common in the Linux world.

In the beginning, I was not used to this form of Linux. Using the double-click installation of WINDOWS, I always feel that the installation of LINUX is very troublesome, and I have to do it myself. /CONFIGURE, MAKE, MAKE INSTALL. In case this software depends on other libraries, then I have to find those libraries myself, just in case. Those libraries depend on other libraries... In addition, the versions of the various libraries are also a problem. If they are not compatible, then find a compatible one.

Why is there so much source code released in the Linux world? Why is the WINDOWS world popular binary file released instead of the source code? Regarding the latter, it is well explained, because many of the source code on WINDOWS are trade secrets and are not public. At the same time, the libraries used by the WINDOWS program are installed in the general system. Therefore, the binary release is feasible and very convenient.

About the previous question, I think one of the benefits of source code release is that you can do some optimization and setup at compile time. For example, the same code can be properly optimized when compiled on a 32 or 64 bit platform. In addition, users can also set some switches at compile time, so optimization during compilation is generally better than runtime optimization.

One of the downsides of source code release is that it requires a higher level of user content. If you run configue, the make command works fine. If you don't go well, you have to change your own files, which is undoubtedly impossible for ordinary users. In addition, the dependencies between the libraries are very troublesome if they are handled manually. Fortunately, in the Linux world, there was a package management system such as YUM APT-GET. Most software can be easily installed.

2, process and its creation CreateProcess VS fork+execv

In the WINDOWS world, the most commonly used WIN32 API for creating processes is CreateProcess and related functions. This function requires a bunch of parameters (features of the WINDOWS API), but many parameters can be simply represented by NULL, TRUE OR FALSE. In addition, you directly tell it which file to execute.

In the Linux world, I know vaguely that fork is used to create a new process. But when I looked at the function description of fork, I was stunned. Because fork does not require any parameters. I am accustomed to the 10 parameters of CreateProcess, and suddenly changed to a function that does not require any parameters, it feels wonderful. On the one hand, it seems that things are a lot simpler, you don't have to figure out every meaning of 10 parameters. On the other hand, I am very confused. How can I tell it that I want to execute a file?

I later learned that the meaning of the process in Linux is different from WINDOWS. The process itself in LINUX is executable. In WINDOWS, a process simply represents the owner of a resource and cannot be executed. To execute, you must have a thread. This also explains in part why the name of the file to be executed must be passed in CreateProcess.

Copyright © Windows knowledge All Rights Reserved