In fact, Unix is very simple.

Source: Internet
Author: User
Tags domain server
Many programming friends of Chen Hao asked me a few questions online. how do I learn Unix? How is Unix so difficult? How can we learn well? And let me give them some experience in learning Unix. Most of the time, I found that friends who asked these questions have two characteristics: 1) fear of Unix and lack of confidence; 2) happiness

Chen Hao

Many programming friends asked me a few questions on the internet. how do you learn Unix? How is Unix so difficult? How can we learn well? And let me give them some experience in learning Unix. In most cases, I found that my friends who asked these questions have two characteristics:

1) be afraid of Unix and have no confidence in it;

2) I like to compare Windows with Unix.

These two features are like two "psychological cues", which imply that Unix is not easy to learn and that Unix is worse than Windows. As a result, you are also hypnotized by your long-term "suggestion. Because, from the very beginning, there was a fear of difficulty, so I felt that Unix was not good, and that it was very difficult. In the end, it would also lead to Unix dislike and dislike. Therefore, in order to correct the "psychological cues" of these friends ". I want to write this article and tell you that Unix is really simple.

Before officially describing "simple Unix", I would like to make a few notes: (to avoid a meaningless debate)

1) This article is explained from the developer's point of view. if a friend does not agree with me, ask and discuss with me from the developer's point of view, I am very welcome.

2) This document will inevitably compare Windows with Unix. This does not mean that I do not like Windows, nor that I want to ask you to give up Windows. We also know that this comparison is meaningless, but because many of my friends have been preemptible to Windows, I must take Windows to turn around the "psychological suggestion ". That's all.

OK. Let's talk about one of the most important features of Unix-"high cohesion and low coupling "! That is to say, various applications in Unix are irrelevant to others. This is the thought that runs through the entire Unix-highly independent modules and programs. This design and practice will make your system more stable and make your system particularly easy to manage and maintain. Unix applications are neatly arranged like a regular army. as long as the commander (kernel) is still there, the system will not be unable to perform self-lifting because of the loss of a certain army. While Windows applications are like a forest. on the Earth's surface, the trees are arranged neatly, but their roots are intertwined and cut continuously, the logic is still messy and extremely complicated.

 

The result of "high cohesion and low coupling" on Unix is that the system basically has a single function of small programs, just like building blocks, when we need to build a custom building, in most cases, we only need to do a simple game of building blocks. The Windows architecture is magnificent. Unfortunately, it is almost impossible for you to get the building blocks from others. It always requires you to imitate or rewrite it.

 

(Do you notice that there is a so-called "green software" when downloading Windows software online "? This is the greatest irony of Windows. when a software is installed in Windows, n dll files are stored in the Windows system directory, and N key values are written in the registry. there are still many unknown actions. When installing software on Unix, you don't have to worry that there will be more messy files in your system directory. It is just as simple as copy, even if it is automatically installed by rpm. after the installation, you can also find the changes made to the system after the software is installed. Therefore, when you distribute your software under Unix, you will feel much easier than Windows .)

 

Another important feature of Unix is that "all devices can operate like Files ". Simple. All I/O operations, such as file preparation, printer, display, terminal, network, floppy disk, tape, USB, CDROM, and so on, are performed in the form of file descriptor. The two most important Unix systems call read/write to perform I/O on all devices. Unix has already created these files for you in the/dev directory. It is easy to use.

 

Many people may think that Unix command lines are too complicated. A command has several parameters that are unusually complex. However, today's Unix applications are still dominated by character interfaces, which exactly reflects the simple characteristics of Unix. This is another feature of Unix-"mutual support of commands". through a pipeline or redirection, commands can be linked together and supported by Shell scripts, even if you want to implement some complex functions (such as a small text database), it is extremely simple.

 

If the above discussion still doesn't convince you of the simplicity of Unix, let's take a look at the simplicity of Unix with some practical examples. Let's try to make the following assumption: "What would happen if we first learned Unix and then switched to Windows when learning programming?

 

1) we create a process in Unix and call it using fork. In Windows, we checked MSDN and found that a system call called CreateProcess can create a process, but we found that this system call has 10 parameters. The fork in Unix does not have a parameter. In this case, do you have a big head feeling? Because in Unix, you cannot see complex system call APIs with 10 parameters.

 

2) the file operation permission in Unix is very simple. the file permission is divided into three groups (myself, the same group, and others). each group is readable, writable, and executable. Two simple systems call chmod/chown. In Windows, if it is NTFS, if you want to set file permissions as a program, you need to first understand what is: SID, what is DACL, what is SACL, what is ACE? there are more than a dozen related system API functions waiting for you. (Refer to my "permission to operate NTFS files by program") you may think that such a complicated security policy is the basis for making the system more secure. since the day that Windows appeared, in terms of security, the performance is no better than Unix. This undoubtedly makes people feel that Windows has done a thankless thing.

 

(Insert: User Switching in Unix is quite simple and convenient. In Windows, user switching will cause you to exit the current user's foreground program. This causes almost all users in Windows to choose to work/access the Internet with the permissions of super users. this completely keeps their machines running naked, once a virus in Windows runs in the system, you can do whatever you want. In Unix, few users operate the local machine as root, because switching users is very convenient .)

 

3) in Unix, users have IDs, user groups have IDs, and processes/threads all have IDs. The ID is easy to understand, just like our ID card. In Windows, the user ID is Token and the process ID is Handle (which is actually a DWORD type). I have seen many questions on the internet asking about the concept of Handle in Windows. I have been wondering why Microsoft does not use a simple and easy-to-understand term? The abstraction is confusing. Although this makes Windows very NB, it will also increase the learning complexity. (The development and learning complexity of Windows is much more complex than that of Unix, and there are too many seemingly profound terms that make people confused)

 

4) Let's take a look at user management and program owner. In Unix, you need to configure the NIS server and NFS server (automatically mount with Autofs), which is concise and clear. In Windows, it is similar to a Domain name (main Domain controller). First, you need to restart the computer to access the Domain (in Unix, you only need to configure/etc/nsswitch. conf file to tell the local user to log on to the source without restarting). For developers, the Unix configuration is completely transparent to the program. Windows domain users need a domain name to distinguish them from local users. When switching a user in a program, Unix only needs setuid/seteuid. Windows has three complex APIs: CreateProcessAsUser, ImpersonateLoggedOnUser, and LogonUser. the complexity of these APIs does not need to be compared. In addition, in the Domain mode, all files under your Document and Setting directory will be put on the Domain server. you need to download these files when logging on to other machines. Finally, I am not worried that your MSN chat records with netizens will be everywhere because of your login. what I am worried about is, can the code you write in such a complex management environment reassure others? :-(

 

5) in Unix, to add your program to the startup service of the system, you only need to configure it in/etc/init. d. Write a script with the stop and start function, and link it to the directories in different startup modes in a special name. Add a startup service in Windows. if you do not write a program, it may be difficult.

 

6) in Unix, if you want to obtain system information. You only need to go to the/proc directory to cat the heap files. All input/thread statuses, command lines, memory/swap zone usage, opened file descriptors, etc., system CPU, memory, swap zone, memory file IO, partitions, information, network, system running status, system devices, and so on. you can view the details of the network, system running status, and system devices in plain text. In Windows, it is not easy to trace the information of the current process of the system, let alone to obtain other information.

 

 

I admire Microsoft's complicated operating system, registry, security policy, OLE, and COM ....... When regedit.exe is opened every time, I do not dare to touch HKEY_CLASSES_ROOT, because I look at the thousands of CLSID in it, and I am a little dizzy.

 

10 years have passed since 1995. Microsoft has introduced a variety of technologies. I still remember two other things in Visual Studio 6.0 called FoxPro and J ++. FoxPro came from Foxbase, and for a few years, J ++ seems to be less than a few years. ActiveX Control is a completely failed technique, and the VB programming language, today it seems, indeed destroyed many very promising programmers. When COM appeared, I don't know how many people still remember a thing called MTS today? Today, I don't know how many people remember a thing called ODBC? In this complicated and chaotic Windows world, is it hard for you to catch up? Today's. NET does not know how many technologies will accumulate over time? On Windows, we have learned a lot of failed or transitional technologies. Our Unix has not changed much since the 1970s S, but the C language that came into being for Unix is still brilliant. I believe that Unix, which has been tested for more than 30 years, is still so simple.

 

Unix is so simple. if you want to learn how to develop it under Unix, the complicated Windows operating systems are all over. are you afraid of such a simple Unix?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.