Unix hate manual

xiaoxiao2021-03-06  111

Unix hate manual

By Simson Garfinkel, Daniel Weise, Steven Strassmann

Chapter 1 Unix

The first computer virus in the world

"Berkeley's two most famous products are UNIX and LSD (a drug), I think this is not a coincidence."

Virus depends on tiny individuals and powerful adaptability to survive. They are not complicated: they do not provide anything for breathing, metabolism, body activities, only sufficient DNA or RNA for prisoning. For example, pneumonia virus is much smaller than the cells they invaded, but they can produce new variants at each pneumonia, causing countless people to die.

A good virus is characterized by:

* There are not many things doing little viruses, so it is not required. Some people think that viruses are not organisms, just some destructive acids and proteins. * The portable virus is often varied to attack different cells in a different manner. It is said that AIDS is made from the virus of the monkey. * Resource * Rapid variation

UNIX has all the above advantages. When it is born, small, there are not many functions, lack the functions needed to truly operating the system (such as file mapping, telling IO, robust file system, device lock, reasonable process inter-process), its transplantability is very good . Unix exhausts the host's resources, there is no system administrator's time care, UNIX will continue to panic (PANIC), Core Dump, hang. Unix constantly varies: the same patch works on a version, can't do it on another version.

UNIX is a computer virus with a user interface.

Standardized those inconsistent

"The greatness of the standard is that it can have a lot" --- Grace Murray Hopper

Since the Unix 80s began to popularize, UNIX manufacturers have been working hard to standardize UNIX standardization. Sun, IBM, HP and DEC have poured millions of dollars on this difficult problem of their own manufacturing.

Why does UNIX manufacturers don't like UNIX standardization?

Many users have been complex enough UNIX, eventually using Windows because their Unix cannot support the application on the UNIX.

If UNIX is standardized, who will buy Sun's machine?

Title: Chapter 2 Welcome New User

Welcome new users like a left round of the six bullets to play Russian roulette Ken Thompson to design a car. Unlike other cars, it has no speed meter, gasoline gauge, and there is no more than those stupid indicators to discuss drivers. If the driver makes any mistakes, a big "?" Will there be a big "?" On the dashboard. "Experienced drivers," Thompson said, "I should know where it is wrong."

A newbie of a computer system requires a friendly system. At least, a decent system will entertain yourself like this:

Command behavior with a logical relationship with a logical relationship consistent command behavior and command line parameters parsing an easy-to-read online document When the command fails, it gives understandable and useful error feedback.

During the construction of UNIX, they never invited their residents. Visiting is a construction worker wearing a hard hat, which is placed in the various corners of this broken wooden house. Unfortunately, not only the participation of the Human Factors engineers, but the needs of the households have never been considered. So the soiletable toilet, central heating, windows, etc. These convenient facilities are hard to add. But architects still proud of UNIX, seems that they don't mind sleeping in a house without a fireworks detector.

In most history of its development, UNIX is just a research tool for university and industrial researchers. With a large number of cheap workstations, UNIX has entered a new era as a platform software. This change has occurred approximately in 1990, its mark is that workstation vendors remove C compilers from UNIX release to reduce cost meeting the needs of non-developing users. It can be seen that the Unix manufacturers have begun to consider the needs of non-programmer users in recent years, starting to provide them with a graphical interface other than the shell. Ambiguous command name

UNIX novices always surprised Unix named commands. Education is not enough to make them understand the simplicity and beauty of both alphabetical orders such as CP, RM, and LS.

People who use the early IO equipment in the 1970s can understand the speed, reliability, and its keyboard of the ASR-33 Teletype. And today, this kind of feedback principle, only need to close a microphone's keyboard, you must use the TELETYPE of the teletype at least half inch to launch a small generator similar to bicycles, and operate the bone in the above Danger of fracture.

If Dennis and Ken use SELECTRIC instead of Teletype, it may be "CP" and "RM" but "Copy" and "Remove" today. (Ken Thompson has been asked if he can redesign Unix he will do what modified, he replied: "I will add an e.") After the CREAT command, "), technology can also limit our choice. Our choice, this example is also.

More than 20 years have passed, what reasons have to continue this tradition? The reason is "the irreplaceable power of history", history is the code and textbooks that exist. If a vendor replaces RM with REMOVE, all UNIX textbooks do not apply to this system, and each shell script that uses RM needs to be modified. And this is not a POSIX standard.

Before an century, the typographic master is often stirred together, and the engineer has designed the QWERTY keyboard, so the problem has been solved because no one can play fast on such a keyboard. The computer's keyboard no longer has a mechanical key handle, but QWERTY's keyboard layout is still in use. Similarly, in the next century, we will continue to use RM.

Accident happens

Users are very concerned about their own data and files. They use computers to generate, analyze, and store important information. They believe that the computer protects their important property. If there is no such trust, they will be shadowed with the relationship between the computer. Unix failed our trust, which refused to protect users using hazardous commands. For example, RM is a dangerous command for deleting files.

All UNIX novices have an unrecoverable deletion of important documents, even an expert and system administrator have encountered. Therefore, the annual loss time, energy can be worth millions of dollars. This is a questionable problem; we don't understand why UNIX has been refused to solve this problem. Does the result is not much tragic?

Unix needs to resume delete functions than other operating systems, because:

Unix file system has no version function

Automatic version maintenance can retain the historical version of the file to prevent the new version from rushing out of the old version. UNIX programmers are not yet checked in error handling Many programs that do not check if all content is written to disk, or whether the file written is present. Some programs always delete the input file.

UNIX shell extension "*" instead of its subcommand

So the command such as RM cannot be inspected "*" these dangerous parameters. Even DOS is also a suggestion for "del *. *". But under UNIX, RM * and RM File1 file2 ... is not distinctive.

Delete is permanent

Unix has no undelete command. Many other safer systems just mark the blocks used by the deleted files for "can be used", then move it to a special directory. If the disk is full, these file blocks will be reused. This technology is not a rocket science, Macintosh proposes the idea of ​​"recycle bin" in 1984, and Tenex used this technology as early as 1974. Even DOS also provides a simple Undelete function, although not always effective. These four issues cooperate with each other to create an important document that cannot be recovered. The solution has long been present, but the UNIX "Standard" version has never been provided.

Welcome to the future world.

"Rm" is end

Many actual terror stories have described these principles. The following is one of a series of stories circulated on the Alt.Folklore.comPuters News:

Date: WED, 10 JAN 90X-Virus: 6From: Djones@megatest.uucp (Dave Jones) Subject: RM * NewsGroups: alt.folklore.computers

Someone wants to perform the following command:

% rm * .o

The result is made:

% rm *> O

Now you get an empty file O, as well as a large space to store it!

In fact, you may not even have O, because the shell's document does not say o is established after the extension is expanded or expanded.

The last book tells how to use RM to get an empty file and a large disk space, the following is another usage:

Date: WED, 10 JAN 90X-Virus: 6From: Ram@attcan.ucpsubject: Re: rm * Newsgroups: alt.folklore.computers

I have been I have been in RM. Once I want to delete some / usr / foo / down, I'll take the following command in / usr / foo:

% rm -r./etc% rm -r ./adm

When I want to delete ./bin directory, I forgot to knock on that point. My system doesn't seem to like this.

When this is hit, UNIX is completely finished. Smart systems will give users a chance (or at least reminding the user to cause system crash).

Unix is ​​ambiguously deleted as an occasional file. For example, you can refer to the FAQ on the Comp.Unix.questions below:

6) How to delete a file?

Maybe one day, you accidentally executed this command:

% rm * .foo

Then I find that you delete "*". You should take this as a class of life.

Of course, a competent system administrator should be scheduled to back up the system. So you'd better ask them in their hands with your file backup.

"One lesson of life"? There is no other manufacturer to treat a defective product in such an attitude. "Adults, I know your fuel tank, but this is a class of life." "Mr. Jury, we will prove the failure of the chainsaw insurance switch is just a class of life on the user." Yes .

Change RM behavior is not a way

After being bitten by the RM, it is often thought of replacing RM with "RM -I", or replaces the RM, put all the deleted files in the ~ / .deleted directory. These tips make users with wrong security.

Date: MON, 16 APR 90 18:46:33 199X-Virus: 6From: phil agre To: UNIX-HATERSSUBJECT: DELETION

On our system, "RM" does not really delete files, but replaces the file, so "undelete" tool can recover the deleted file.

This feature makes me no longer care about the delete file, and I can find it back anyway. However, I am wrong. The deletion in Emacs does not support this feature, and the Dired command is also true. This is of course because file recovery is not a function of the operating system. So, now I have two concepts in my mind, one is a "deleting" file, one is a "rm'ing" file. When my hand wants my brain to delete a file, I always divide these two concepts again.

Some UNIX experts have made ridiculous conclusions, they think it is best to make RM more friendly. They argue that let UNIX more friendly efforts are often counterproductive. Unfortunately, they are right.

Date: Thu, 11 Jan 90 17:17 CSTX-Virus: 6From: Merlyn@iwarp.intel.com (Randal L. Schwartz) Subject: Don't overload Commands! (Was Re: rm *) NewsGroups: alt.folklore. Computers

Don't let people replace standard commands with the "safety" command.

(1) Many shell programs are surprised by the multi-mouth RM, and they will not think that the deleted file still has disk space.

(2) Not all deleted operations are safe, and some households will generate an illusion that everything can be recovered.

(3) Those unbolded orders are especially hateful for system administrators. If you want to have a "RM" with a confirmation function, use the following command:

% Alias ​​Del RM -I

Don't replace RM!

Recently, there have been a survey of system administrators on Comp.unix.Questions, let them say the most horrible system management story. Within 72 hours, there were more than 300 responses. Many related to the files we described above. It is ridiculous, these can be unix masters. However, they are defending the "Unix is ​​not friendly".

Isn't users are not friendly? Unix is ​​friendly for system administrators? Please see

Date: WED, 14 SEP 88 01:39 Edtx-Virus: 6FROM: Matthew P Wiener To: risks-list@kl.sri.comSubject: "Single Keystroke"

On UNIX, even if there is an experienced user, RM is also missed. I have never misuse a file, but one day, I use! R Repeat a history command, I am surprised to find that I am running "rm -r *".

Why can't you have a shell without a History function?

I also heard a user attempt to delete a file called "*", so there is no permission.

This user also wants to modify the shell to avoid expanding the *. Unfortunately, this remedy is like a lacquer in the water seepage wall, and the standard is not true.

Online help

The number of users read printing documents is less than they participate in elective votes. Only online documents that can be used is useful. Let's take a look at how UNIX's man is disappointed with the new user that needs it.

Not each command is equal, some are external commands, some are internal commands. Some man Page, some are not. Unix requires you to distinguish these commands. For example, WC, CP, and LS are external commands, which are Man Page, while fg, jobs, set and alias (where are these long file names come from?) Are internal commands, which do not have Man Page.

Unix tells the newbush to help with the "man command" command, they don't know that all commands are not all commands. In addition, if their shell sets some inexpensive, they can only ask the masters to get help. Error message and error check? no way!

Novice is easy to make mistakes, such as using the wrong command, or with the wrong option. The system should be able to identify these errors and feedback to the user. Unfortunately, UNIX programs have never bother themselves. Instead, UNIX often mixes all kinds of errors until a fatal result is created.

In the first section, we explained how RM is easily deleted. But you may not know that you can easily delete files without RM.

Want to delete your files? Try the compiler

Some CC versions often do not consider user possible input errors, and delete some source code files. Some undergraduates often have a way.

Date: Thu, 26 Nov 1992 16:01:55 GMTX-Virus: 6From: tk@dcs.ed.ac.uk (Tommy Kelly) Subject: Help! NewsGroups: cs.questionsorganization: Lab for the Foundations of Computer Science, Edinburgh UK

I just want to compile the program:

% cc -o doit dress.c

I accidentally knocked it:

% cc -o doit.c doit

Don't say that my DOIT.C is rushed away. Is there a way to recover my procedure? (I did a whole morning)

Some other programs have the same behavior:

Date: Thu, 1 July 1993 09:10:50 - 0700X-Virus: 6From: Daniel Weise To: UNIX-HATERSSUBJECT: TARRED and Feathered

After several efforts, I finally downloaded a 3.2m file from a fragile FTP site in Europe. This Untar it. I knocked on the command:

% tar -cf hesis.tar

…no respond.

Old days!

Is it necessary to use the X option instead of C?

Yes it is.

TAR is not given an error message saying that there is no input file?

No.

Does TAR feel wrong?

No.

Tar is really not really Tar?

Yes it is.

Does TAR have covered with THESIS.TAR?

Of course, this is UNIX.

Do I still need to spend 30 minutes to download this file from Europe?

Of course, this is UNIX.

I must definitely have a lot of people who have encountered this unfortunate, such as: error message, file version, confirm whether the user wants to overwrite an existing file, and so on. Tar seems to be intentionally giving users trouble.

This bug is more dangerous for system administrators who often backed up with Tar. Many system administrators have used "TAR Xf ..." in the backup script. When you need to restore your backup, I didn't do anything.

If you want to know if there is any other horror command, please follow the decomposition.

The last book tells how cc, tar, etc. helps you delete important files. The power of UNIX is certainly unlimited.

Because there is no error check, in the support of many "Unix Power Programming Tools", users have various options to delete their important files.

Date: Sun, 4 Oct 1992 0:21:49 PDTX-Virus: 6From: Pavel Curtis To: unix-hatssubject: So Many Bastards to choose from ...

I have a program that is running, used to provide network services, and check the internal state of the system every 24 hours. One day, I cd to the directory where the Foo is located, because this is not a development directory, I want to see how the foo is version. The code is maintained by RCS, so I naturally use the following command:

% Ident Foo

Don't take the sink of RCS, don't manage the iderter how to be mad. My trouble is, my finger is self-selected, INDENT, INDENT, like a word rather than Ident:

% Indent foo

Indent is a stupid C code style conversion tool for UNIX. Is that written for the independed bastard? Is it true for the input file (How to see if the suffix of the file is .c)? I think you know the answer. Moreover, this SB (SAID BASTARD) thinks if you only give a parameter, then you just want to perform online style conversion. But don't worry, this SB takes into account the trouble that may bring, he saves a backup foo.bak. However, is he just changed the FOO? No, he chose to copy (no doubt, the programmer written in Indent has opened the foo when preparing backup, and the rename system call is later).

Now, you may know what happened ...

My foo is running in the preparation of the page fan, I found that the original executable is not there, this is not a good thing, so my Foo collapsed, I lost 20 hours of system status information.

Naturally, those designed (cough) Unix bastions are not interested in complex file version, and this feature can save my life. Of course, those bastards have never thought of locking files that are preparing to fans out, is it?

There are so many bastards to choose, why not kill them?

Pavel

Imagine a paint that emits chlorine, according to the instructions, it is not a problem in outdoor, but if you use it to brush your bedroom wall, your head is bigger. How long does this paint can survive in the market? Of course, it will not exceed 20 years.

Error information joke

Will you laugh when you see a plate of vegetables in the customer's head? Unix haball. But when the helpless users have to solve the error message, they are the first to laugh.

Some people organize some Unix the most ridiculous error messages and released him on the usenet. They use C shell.

% RM Meese-EthicsRM: Messe-Ethics Nonexistent

% Ar M Godar: God Does Not Exist

% "How Would You Rate Dan Quayle's Incompetence? Unmatched".

% ^ How Did The SEX CHANGE ^ Operation Go? Modifier Failed.

% IF I Had A (For Every $ THE CONGRESS SPENT, WHAT WOULD I Have? Too Many ('S

% makemake: don't know how to make love.......

% Sleep with Mebad Character

% got a light? no match

% Man: Why Did You Get A Divorce? man :: Too Many Arguments.

% ^ What is saccharine? Bad subsstitute.

%% blow% bulk: no such job.

The following humor works from the Bourne Shell:

$ PATH = preteding! / Usr / ucb / which senseno sensor in pretending $ Drink

$ mkdir matter; cat> Mattermatter: Cannot Create

UNIX attitude

We show a very bleak picture: the fans and general command names, inconsistencies and unable to expect results, dangerous commands are not protected, unacceptable online documents, as well as a sudden job in error checking and fault tolerance. Those who visit UNIX are not to get warm hospitality, they are not tourists in Disney Park, more like the United Nations peacekeeping force in the implementation of the task. How will UNIX make this look? As we pointed out, some of them were caused by historical reasons. But there are other reasons: that is, Unix culture formed for many years, this culture is called "UNIX philosophy".

Unix philosophy is not a manual from a Bell Lab or UNIX system laboratory. He is naturally formed, which contains many people's contributions. Don Libes and Sandy RESSLER have made good summary of UNIX philosophy in "UNIX Life":

Small is a US 10% work to solve 90% of the task If you must make a selection, choose the easiest thing.

According to the practical performance of UNIX programs and tools, the more accurate summary of UNIX philosophy should be:

Small procedures are better than correct programs that can be accepted if they must be selected, and the smallest responsibility is selected.

Unix has no philosophy, UNIX is only attitude. This attitude pointed out that simple work is better than complex complete work. This attitude indicates that the programmer is more precious than the user's time, even if the user is much more than the programmer. This attitude indicates that the minimum requirement is sufficient.

Date: Sun, 24 DEC 89 19:01:36 Estx-Virus: 6FROM: David Chapman To: UNIX-HATERSUBJECT: KILLING JOBS; The Unix Design Paradigm

I have recently learned how to kill the task on UNIX. In this process, I realized a lot of Unix's powerful and wisdom, I would like to share with you.

Most of you don't have UNIX, so you know how UNIX the task is estimated to be used. However, some of you, including me, may often run some TEX tasks, then learn to kill the task is especially important. The "kill" command inherits UNIX design principles, so some of the following experiences have more common sense.

In UNIX you can use ^ z to hang a task, or terminate a task with ^ C. But Latex intercepted ^ c. As a result, I often make a bunch of Latex tasks. I don't care about it, but I still feel that I should find a way to remove them.

Many operating systems have commands such as "kill", Unix is ​​no exception. "Kill" on most operating systems is only used to kill the process. But Unix is ​​more common: "kill" is used to send a signal to the process, which reflects a design principle of UNIX:

Try to make the operation universal, give the user powerful force (Power)

The "kill" command function is very powerful; you can use it to send a variety of signals to the process. For example, 9 this signal is used to kill the process. Note that 9 is the largest one, which reflects another design principle of UNIX:

Use the simplest name that can reflect functionality

On the operating system I know, "KILL" without parameters is used to kill the current task. Single Unix "kill" always requires parameters. This reflects a wise design principle of UNIX:

Try to use long parameters or tips to prevent users from accidentally referring to the design principles of themselves, I don't want to list them, but I still want to mention Logout and file deletion on UNIX. Realization, I hope you know what I mean.

On the operating system I know, the parameters accepted by "Kill" are the task name. This is not a good choice, because you may have many Latex tasks run at the same time, and they all have the same task name "Latex". So "Kill -9 Latex" may produce ambiguity.

Like other operating systems, UNIX provides a command "jobs" listing the task. Here is an example:

ZVONA @ rice-chex> jobs [1] - stopped latex [1] - stopped latex [1] stopped latex

This allows you to identify a task with a JOB number (indicated in []).

If you are affected by those who have not been carried out, you will want to use "Kill -9 1" to kill the first LATEX task. But you will find the following error message:

Zvona @ rice-chex> KILL -9 11: Not Owner

The correct approach is to use the process number, such as 18517. You can use the "ps" command to get it. When you find the corresponding process number, you only need:

ZVONA @ rice-chex> kill -9 18517zvona @ rice-chex> [1] Killed Latex

Note that UNIX gives you a prompt before your task is really killed. This reflects a UNIX design principle:

For the feedback to the user, you can say less, you can say that you can say nothing later. Users who may cause too much information may cause brain damage.

I hope that these experience can be useful to everyone. During this study process, I have been deeply attracted by UNIX design philosophy. We should all learn from the elegant, powerful and concise middleness of the UNIX kill command.

The second chapter is over, I have experienced so many difficulties, you are not a newbie, and the next book will introduce the documentation of UNIX, or there is no documentation in Unix.

Title: Chapter III Documentation

OK, not a novice you may want to learn from UNIX. Nice, UNIX documents are what you need.

Documentation document

"One advantage of using UNIX operating system teaching is that the student's school bag can install all UNIX source code and documentation."

- John Lion, New South Wales University, in 1976, talking about UNIX version 6 point.

For many years, there have been three simple ways to obtain UNIX related knowledge:

Read the source code written a mobile phone to write UNIX, call (or email)

Like Homer's epic, UNIX is tangled orally. If you don't become a kernel hacker, you can't be a serious UNIX user - or at least there is a tentacker hacker with a tentacker. The existing document - Man Handbook - but some memorandums you have already known for what they are doing. Unix's document is so simple, you can read it in an afternoon.

Online document

The Man Tool is the basis for the UNIX document system. Man accepts the parameters you entered, find the corresponding document file, output it to NROFF (some text format macros) that do not have other places on some places), and final results are sent to PG or more.

First, these fragmented documents are called "Man Pages" because these documents are more than one page (most cases are less than one page).

MAN is a good thing for that era, but that era has already returned.

Over the years, MAN systems have developed mature. It is worthy of praise that it doesn't make the code chaotic program like UNIX, but it has not become more useful. In fact, in the past 15 years, UNIX's documentation system has only two improvements: Catman. Programmer "surprise" found that in addition to NROFF format, they can store the handled document file, so that the document is called The speed is faster. For today's fast processor, Catman doesn't seem to need it.

However, many NROFF processed document files still occupy a few megaby disk space. MakeWhatis, Apropos and Key (finally constituted Man -k function) is a system that indexes to the Manbook, so that even if the exact name of the program can be queried even if you don't know the exact name of the program.

At the same time, the momentum of the electronic publishing has already exceeded the MAN manual. Using today's hypertext system you can use the mouse from an article to another article; Compared with the MAN manual, the "See Also" section is only available at the end, so that the user will be mans themselves. What is the index function of the online document? Today you can buy an Oxford English dictionary on the CD-ROM, which has an index on each of the words; but the Man manual is still indexing the command name and description line. Today, even DOS provides an indexed hypertext document. However, the Man manual is also a format of 80 columns 66 rows suitable for DEC print terminals.

Fair point, some manufacturers can't see it, provide their own hypertext online document system. On these systems, the MAN manual has come to the end of evolution, often not outdated, it does not exist at all.

"I know it is here, but I can't find"

For those who are still using the Manbook today, the biggest problem is to tell MAN's manual you want. It is easy to find the Man's manual: all in / usr / man. Later, the Man Handbook is divided into different directories in chapters: / usr / man / man1, / usr / man / man2, / usr / man / man3, etc. Some systems even put the "local" manual under / usr / man / man1.

When the AT & T release system V, the situation becomes puzzled. The / usr / man / man1 directory becomes / usr / man / c_man, which seems to be better than the number. In some systems, / usr / man / man1 becomes / usr / local / man. Those companies that sell UNIX applications began to build their own Man directory.

Finally, Berkeley modified the Man program to find a series of directories specified in the Environment Variable $ MANPATH. This is a great idea, there is only one small problem: it doesn't work. (I will omit 100 words, because I am too lazy, the content is too late, the man on Linux is still good, in addition to the MAN manual of the shell internal command, of course, Man Bash is a choice - me).

Is this an internal document?

Some big UNIX tools also offer their own documents. Many online documents of the program are "Usage" (usage), which is called. Below is the "use" description of awk:

% awkawk: usage: awk [-f Source | 'cmds'] [files]

Is it very useful? Complex procedures have a more in-depth online document. Unfortunately, they sometimes don't seem to be a program you are running.

Date: 3 Jan 89 16:26:25 EST (Tuesday) X-Virus: 6From: Reverend Heiny to: UNIX-HATERSSUBJECT: A Conspirace Uncovered (conspiracy is exposed)

After a few hours of concentrational research, I got an important conclusion:

Unix is ​​a shit (UNIX SUCKS) now, you may feel surprised, but this is the fact. This study has been confirmed by researchers throughout the world.

More importantly, this is not just a booth, but a thin and sticky stinky shit, is a big smell. Take a look at this example, you will know:

Toolsun% Mailmail Version SMI 4.0 SAT APR 9 01:54:23 PDT 1988 TYPE? For Help "/ usr / spool / mail / chris": 3 Messages 3 New> N 1 Chris THU DEC 22 15:49 19/643 Editor Saved "Trash1" n 2 chris tue jan 3 10:35 19/636 Editor Saved "trash1" N 3 Chris Tue Jan 3 10:35 19/656 Editor Saved "/ TMP / MA9" &? Unknown Command: "?"

What kind of system environment (especially this guy who can drive, vote, drink beer age) will reject a command it makes it?

Why is the user manual so separated from reality?

Why is these mysterious orders do not match this?

We don't know what heiny's question; like some of the problems mentioned above, this bug seems to have been revised. Or, it is transferred to other programs.

Date: Tuesday, September 29, 1992 7:47 PMX-VIRUS: 6FROM: MARK Lottor to: UNIX-HATERSSUBJECT: No Comments Needed (no need to say)

FS2 # add_clientusage: add_client [options] ClientsAdd_client -i | -p [options] Clients-I Interactive Mode - Invoke Full-Screen Mode

There are some options, here is omitted]

FS2 # add_client -i

Interactive Mode Uses no Command Line Arguments

How to get a real document

In fact, UNIX's best document is often used in Strings handler binary code. You can get the file name, environment variable, unapproved option, weird error message, and so on all programs. For example, if you want to know how the CPP looks for the header file, you'd better use strings instead of Man:

Next% Man CPP

NO MANUAL Entry for CPP.

Next% strings / lib / cpp | grep // lib / cpp / lib // usr / local / lib // cppnext%

Um ... don't worry

Next% ls / libcpp * gcrt0.o libssy_s.acpp-precomp * i386 / m68k / crt0.o libsys_p.a pOSIXCRT0.Onext% strings / lib / cpp-precomp | grep // *% s * ///% s / usr / local / include / NextDeveloper / Headers / NextDeveloper / Headers / ansi / NextDeveloper / Headers / bsd / LocalDeveloper / Headers / LocalDeveloper / Headers / ansi / LocalDeveloper / Headers / bsd / NextDeveloper / 2.0CompatibleHeaders% s /% s / lib / % S / SpecSNext%

I am a fool. Nextstep's CPP uses / lib / cpp-precomp. You can't find this in the Man's Manual. Next% Man CPP-Precomp

No Manual Entry for CPP-Precomp.

OK. What all this is because? Where did this come from? Next decomposition.

The last book is said that the source code is the best and unique document, the root cause is because UNIX is ...

For programmers, not users

Don't blame Ken and Dennis because of the documentation of UNIX. When UNIX just started to establish a document, there is no compliance with the industry popular document standards, some bugs and potential traps, not the functionality of the program, is recorded, because people who read these documents are often UNIX system developers. For many developers, the MAN manual is just a place to collect bug reports. Those ideas that provide documents for primary users, programmers and system administrators are new. Sadly, this concept is not very successful due to the Unix document system established in the 1970s.

The UNIX World recognizes the status quo of these documents, but does not think there is a big deal. "UNIX Life" is objectively explained by UNIX to the document:

UNIX source code is the best document. After all, this is the system used to determine how to run the documentation. Document is used to explain the code, often written in different times, and these people are often not writing code. You should think of these documents as guidelines. Sometimes these documents are just expectations.

However, a more general approach is to find unsourized usage methods and function descriptions in the source code. Sometimes you find that the functions recorded in some documents are not implemented.

This is just for the user program. For the kernel, the situation is even worse. Until recently, there is no documentation for the device driver and internal-core calling functions provided by the manufacturer. Some people joked: "If you feel that you need to read the documentation about the kernel function, you are likely that you don't use these functions."

The truth is probably more evil. The reason why there is no kernel document is because AT & T looks its code as a commercial confidential. If you want to write a book that describes the UNIX kernel, then you will wait for the Sub.

Source code is a document

Life is destined, AT & T's plan is compromised. Due to no documentation, the only way to understand the kernel and applications is to read the source code. As a result, UNIX source code was madly pirated in the initial 20 years. Consultants, programmers and system administrators to engage in unix source code is not to recompile or produce their own UNIX version, they need documents, and source code is the only choice. Unix source code from the university flows to the surrounding high-tech company. This is of course illegal, but there is an enabled: UNIX manufacturers are not enough.

This is not the secret of what is worthy of money in the source code. All people who have read UNIX code were thrive at a rough confirmation:

/ * You are not expected to understand this * / (/ * Didn't expect you to understand * /)

Although this line comment starts to appear in the UNIX V6 core, almost all the original AT & T code is similar, which is full of macros that have been optimized and weird. The register variable is crown with the name of P, PP, and PPP. "This function is recursive" seems to indicate what is difficult to understand. In fact, the attitude of AT & T is good at the document is just a reflection of the hidden attitude of its writing code.

To identify a footprint man is actually very simple: you will see the paint on the crack, a patch that picks up one, all things are barely enhanced by tape and chewing gum. It must be recognized: If you want to build and redesign from head, you must think more, and more effort.

Date: Thu, 17 May 90 14:43:28 -0700x-Virus: 6From: David Chapman To: UNIX-HATERS This is a paragraph in Man Man, very interesting:

Diagnositics

If you use the -m option and give the path do not exist, then the output error message may be a bit wrong. For example, the / usr / foo / directory does not exist if you run:

MAN-M / USR / FOO LS

Then the error message you get is "No Manual Entry for LS" ("Does No LS Manual Record"). Tell your directory / usr / foo when the correct error message does not exist.

There are Kung Fu to write this paragraph, I am afraid enough to modify this BUG.

Silent Unix: Curriculum Settings Suggestions

Date: Fri, 24 APR 92 12:58:28 PTX-Virus: 6FROM: CJ@eno.corp.sgi.com (C J Silverio) Organization: SGI TechpubsnewsGroups: Talk.Bizarresubject: UNIX WITHOUT WORDS (Silent Unix)

[In a fierce debate about document unused, I proposed the following suggestions. I am small, so I dare to open now for your reference. ]

UNIX OHNE WORTER (no turning - ME)

I was deeply convinced by the document that was walking here. In fact, I am further thinking that the document is drug, I have caused it for its dependence. With the help of a profession, I think I can quit it.

Moreover, my conscience tells me that it is no longer born with this drug. I decided to go back to the math research institute to reborn, completely from this parasitic occupation.

Although the document following this seems to show how deep it is poisoning, but I still think that the next version should be provided to the user. This is just a temporary move, and it will fill it later.

This is my suggestion:

Title: "Silent Unix"

Object: unix newbie

Summary: Provide a general policy that uses UNIX without document conditions. Shows the general principles of any operating system without document conditions.

content:

Introduction: "No Document" Philosophy Introduction Why is the manual why the MAN manual is a demon? You should also read this document "This will be the last document you read!"

Chapter 1: How to guess what may be present?

Chapter 2: How to guess the command name

Unix's Weird Thumbnock Name Act: GREP

Chapter III: How to Guess Command Options

How to crack the weird instructions: TAR know how to know when it is an important case: FINE

Chapter 4: How to know the correctness: No news is good news

Restore from errors

Chapter 5: Oral Tradition: Your friend

Chapter 6: How to get and maintain a living UNIX master

How to feed your master How to make the master happy to provide the importance of all newsgroups Why is your master need the fastest computer Free Can?

Chapter 7: Common Troubleshoot: Your master ignore you

How to identify stupid problems safely put forward stupid problems

Chapter 8: How to Belt pressure

How to treat failed

Note: May only have 6, 7 chapters really need. Yes, this is the right road: I call it "Unix Master Domestication Guide".

OK, there is no document. The next book will take you into the beautiful world of Sendmail, why "The feeling of sendmail is the same as the flower willow disease."? Next decomposition.

Title: Chapter 8 CSH, Pipes and Find (Part 1)

The Unix Romance started again. This book will be a table of Sendmail and flower willow disease. We can communicate privately with the history of history and sexual disease struggle. As a programmer, you may be more interested in the UNIX programming environment, so this section describes the history of UNIX shell. I gpl, you didn't spend money, so I can only let me put, what you eat, don't talk nonsense.

The benefit of GPL is that you don't have to be responsible for your work, you don't have to be responsible for users, so SourseForge is full of tight free projects. I hope that my people can understand this. All the beginning is not for what value, responsibility, the past or the future, all this is not for the present, all this is just from pass.

In each of the bubbles discharged in the sea, every time in the past, every pain in the past, in the past, in the weather forecast and news broadcast in July, in July, in July, in July, in July. In July, the Temple in July is in the Yifuti and Furong in the long rope day in the long rope day. It does not have to seek significance.

Chapter 8 CSH, PIPES and FIND

Powerful tools give strong fools

"Some operating systems have never been planned to plan, so that I have to name it with ruminant noise (awk, grep, fsck, norff), I think this will be nausea."

-- anonymous

The so-called "powerful tool" of UNIX is a scam. This is just that UNIX is a hit of the mosaic for the commandments and tools. The real powerful tool does not require users to pay too much effort to provide powerful features. Anyone who will make the cadre and drill should use electric to modify cone and electric drill. They don't need to understand electrical, motor, torque, electromagnetic, heat dissipation or maintenance. They only need to power it up, bring safety glasses, and turn on the switch. Many people do not have safety glasses. You can't find a deadly defective tool in the Hardware store: They are not at all, they are not able to put on the market, that is, they are being attached to the head.

The initial goal of UNIX designers is to provide simple tools, however now is full of excessive design and bloated features. For example, the command of the LS file has 18 options, providing various functions from sorting to the specified display column number, and these functions can be better (formerly this). The Find command except for the Find file, the file is also outputted in the CPIO format (and this function is greatly implemented using the Unix reputation wolf.). Today, with the Unix's electric drill will have 20 knobs, with an inexpensive power cord, do not match 3/8 inch and 7/8 inch drill bits (this will be described in the BUG chapter of the manual).

Unlike the tools in the hardware store, many UNIX powerful tools are defective (sometimes fatal on files): such as Tar's unacceptable file name; for example, the UNIX debugger is always collapsed, this also Not enough, its core file will override your own core, let you take the debugger to debug the Core generated in the debug debug.

Shell game

Unix inventors have a great idea: implement the command parser as a user program. If the user doesn't like the default command parser, he can write one yourself. More importantly, shell will evolve, so shell will continue to advance, become more powerful, flexible and easy to use, at least theoretically.

This is really a great idea, but it is intimate. The gradual increase in functions is a mess. Because these functions have not been designed, it is only evolved. Like the curse they have passed by all programming languages, those existing shell scripts that use these features have become the biggest enemy of the shell. As long as there is a new function to join the shell, someone will use it in his script so this feature is not old. Bad ideas and stinking strength often can't die. So you got an incomplete, incompatible shell hodge (the following description of each shell) comes from their respective MAN Pages):

The SH is a command programming language for executing commands from terminals or files. JSH and SH, but with CSH flavor Work Control (Job Control) CSH C Type Syntax SHELLTCSH Emacs Edit Taste Cshksh Kornshell, your other command and programming language zsh z shellbash gun bourne-again shell (GNU Bourne Reset Shell )

The screwdriver and saw in the hardware store, although it may come from 3, 4 different manufacturers, but the operating methods are almost. Typical UNIX is deposited by hundreds of programs in / bin or / usr / bin, and they come from many self-righteous programmers, with their own grammar, operating examples, and use rules (this can be used as a pipe, and that one is temporary Document), different command line parameters, and different restrictions. Take GREP and its variant fgrep, egrep, which is the fastest? Why do they accept the parameters, even the understanding of the regular expression is not the same? Why can't you have a program to provide all features? Where is the responsible guy?

When all the various types of orders are deeply branded in the mind, you can't avoid being thrown.

Shell Crash

The following message comes from the BBS of the Columbia University Compilation Principles.

Subject: Relevant Unix Bugoctober 11, 1991

Classmates for W4115x courses:

We have just learned an activity record, parameter passing and function calling rules (do you know the following input will crash right right right?

:!! Xxx% s% s% s% s% s% s% s% s

Do you know why?

The following questions are for you to think:

What will shell do in "! Xxx"?

What will she do when shell encounters "! XXX% S% S% S% S% S% S% S% S"?

Why will CSHELL crash?

How will you modify the code to solve this problem?

The most important thing:

When you (yes, you) use this future operating system with 21 characters, do you think is the weather?

You can try it yourself. According to UNIX design, if the shell is falling, all your processes will be killed, and you will also be kicked out of the system. Other operating systems pop up the debugger when encountering illegal memory access errors, but not UNIX.

May this is why Unix Shells does not allow you to dynamically load your module in the address space of the shell, or call the functions in other programs directly. If this is too dangerous. Step by error, 唉, you have been kicked out of the door. The stupid user should be punished, and the programmer's mistake is not tolerable.

We will enter the colorful UNIX grammar world.

Half a year ago, I said how you go to play shell game, it is estimated that you have already played yield, but don't worry, below, this round to play with you.

Welcome to the metasyntacitic zoo C shell's metamorphological operator brings a lot and quote related issues and confusion. The meta operator converts it before being executed. We call these operators to operate because they don't belong to the syntax ingredients of the command, they act on the command itself. Most programmers are not unfamiliar with the meta operators (sometimes called escape operators). For example, the backslash (/) in the C string is a meta-syntax operator; it does not mean yourself, but instructions on the following characters. If you don't want this, you must use the reference mechanism to tell the system to handle the meta operator as a general character. Go back to the example of the C string, if you want to get a backslash character, you must write //.

The simple reference mechanism is hard to work in C shell, because the SHELL and the programs that it executes, uniform. For example, the following is a simple command:

Grep string filename;

The parameter string contains a character, such as?, [, And], but these characters are the monolithic operator. This means that they must be referenced. However, sometimes it may not need this, this is related to what kind of shell and environment variable you use.

This is more complicated if you want to find a point (.) Or other mode starting with the horizontal bar (-) in the string.

Be sure to remember the correct reference to the metamorphism. Unfortunately, like pattern identification, all parts of the operating system are full of reference standards that are incompatible.

C shell's metamorphological zoo has raised seven different meta operator families. The fight is shifted, and it has been full of blindness in the zoo in an eye, and the cage is no longer steel, but uses tin. The small rubbing between the animals is constantly. These seven ways to convert the shell command line are:

Alias, Unalias

Command output replacement`

File name instead *,?, []

History alternative!, ^

Variable replacement $, set, unset

Process replacement%

Quote ', "

The result of this "design" is that the question mark (?) Is always as a single character matching, which will never be passed to the user program as the command line parameter, so don't want to use the question mark as a help option.

If these seven metades have a clear logical order and definition, then the situation will not be too bad. It is not the case:

Date: MON, 7 May 90 18:00:27 - 0700 Sender: Andy BEALS Topic: Re: Today's Gripe: FG% 3 (Today's Nothing: fg% 3) Receive: Unix-Haters

You can use% Emacs or% E to restore a task (if unique), you can use%? Foo, if "foo" appears in the command line.

Of course,! EMA and!? Foo can also be used for historical commands.

However, the Pinheads of the UCB did not think of it! • Foo may be accompanied by the editorial command:

!? foo: s / foo / bar & /: p

What is the so difficult to scan a editing character?

Even if the Unix "experts", I have to hara. Let's take a look at this example of Milt Epstein, he wants to write a shell script to get the actual line of the actual knocked, not the result after the shell. He finally found that this is not easy, because shell has made too many "good things" for the command. To do this, you need a variety of rare deformation techniques, and even Unix experts will also see. This is the typical approach of UNIX: It's just because of the simple things, this is just because these things have never been carefully considered when UNIX is born:

Date: 19 AUG 91 15:26:00 GMT Sender: Dan_Jacobson@att.com Topic: $ {1 "$ @"} shell scripts recipient: comp.emacs.gnu.emacs .hell >>>>> on sun, 19 arg 91 18:21:58 - 0500 >>>>> MILT EPSTEIN Write:

What does it mean by mill> "$ {1 " $ @ "}"? I estimate that this is used to read the rest of the command line parameters, but I don't dare.

This is a way to complete copy command line parameters / bin / sh.

It means: If there is at least one parameter ($ {1 ), all parameters ("$ @") are used instead to keep all blank characters.

If we use "$ @", then "" "instead of empty parameters we want without parameters."

So why not use "$ *"? The MAN manual of SH (1) is said:

The parameters and commands between the double quotes will be replaced, and the shell will add a reference to the result to avoid parsing the space or generate a file name. If $ * appears in double quotes, the space between the various parameters will be added to the reference ("$ 1 $ 2 ..."), and if $ @ appears in double quotes, the space between the various parameters will not Plus the reference ("$ 1" "$ 2" ...).

I think $ {1 "$ @"} can always be compatible with the "version 7" shell.

Old days! Always compatible with "Version 7".

Listening to "chDIR" or listening to "CD"?

Unix is ​​easy to hand in a long evolution process. These UNIX system developers lead UNIX to different directions, and there is no one in them to consider their own practices will not conflict with others.

Date: MON, 7 May 90 22:58:58 Edt Sender: alan bawnden Topic: cd ..: i am not Making this Up (cd ..: This is not my fabrication Received: Unix-Haters

What is the order that can be more direct than "CD"? Let us see this simple example: "CD FTP". If there is a child directory in my current directory / home / ar / alan called "ftp", then it turns into my new current directory, now I am under / home / ar / alan / ftp. Simple?

Now, you know "." And ".."? There are two records per directory: "." Refers to this directory yourself, ".." refers to the father directory. In the above example, if I want to go back to / home / ar / alan, just knock "CD ..".

Now suppose "FTP" is a symbolic link. Suppose it points to the directory / COM / FTP / PUB / ALAN. If "CD FTP" is executed, my current directory will be / com / ftp / pub / alan.

Like all other directories, / COM / FTP / PUB / ALAN also has a record ".." record, which refers to the parent directory: / COM / FTP / PUB. If I want to enter that directory, I will knock into the command:% CD ..

Guess what I am now? I returned to / home / ar / alan! Shell (accurately said TCSH used in artificial intelligence laboratories) I think I actually wants to return to the directory with symbolic links. Now I have to use "cd ./ .." to enter / com / ftp / pub.

Shell Programming

SHELL programmers and the dinosaur manufacturers in Jurassic Park are some similar. There is no complete material needed in their hands, so I have to fill some messy materials. Despite endless confidence and abilities, they don't seem to always control those who have lived.

In theory, there is a lot of benefits using shell programming than using C language: shell program transplant is easy. This refers to the program written using the shell "programming language" to run on different architectures and different UNIX variants, because the shell will resolve these programs instead of compiling these programs into machine code. Moreover, standard UNIX Shell SH has become an indispensable part of UNIX since 1977, so you can find it on many machines.

Let's verify this theory, write a script to list all the files in the directory, and use the file command to display the type of file:

Date: Fri, 24 Apr 92 14:45:48 EDT sender: Stephen Gildea Topic: Simple Shell Programming (Simple Shell Program) Received: UNIX-Haters

Hello students. Today we will learn "SH" programming. "SH" is a simple and useful program, let us first look at the basic example:

Print a type of all files in a directory

(I heard what you said later! The students who have already written can write a script to start a X11 client remote, don't noisy!)

While learning SH programming, we have also hoped that our procedures are robust, portable and elegant. I assume that you have read the corresponding MAN manual, so this implementation should be very simple:

File *

Very good, is it? Simple answers give simple questions; symbols * used to match all files in the directory. Well, not necessarily. The files starting with a point (.) Will be ignored, * will not match them. Perhaps this situation rarely occurs, but since we want to write a robust program, we will use a special option for "LS":

For file in `ls -a`

DO

FLIE $ FILE

DONE

What an elegant, how strong! However, hey, "ls" on some systems do not accept the "-a" option. No problem, we use the "-a" option, then remove it "." And "..":

For file in `ls -a`

DO

IF [$ file! =. -A $ file! = ..].

File $ file

Fi

Done is not so elegant, but at least a strong and portable. what did you say? "Ls -a" is not where you can use? No problem, we use "ls -f" okay. It's still a bit. I hope that you can see all these things from the MAN manual.

Oh, it may not be so strong. Any character can be used in addition to the slash (/) in the UNIX file name. If there is a space in the file name, this script is finished, because shell will pass it as two file names to the "file" command. But this is not too difficult to deal with. As long as we put it in the reference: for file in `ls -f`

DO

IF [$ file "! =. -a" $ file "! = ..]

THEN

File "$ file"

Fi

DONE

You may have already seen it, we just reduce the problem, but it is still not completely solved. Because the wrap can be used in the file name.

Our script is not that simple, it seems to re-evaluate the method we use. If we don't use "LS", you don't have to deal with its output. how about this:

For file in *. *

DO

IF [$ file "! =. -a" $ file "! = ..]

THEN

File "$ file"

Fi

DONE

looks great. Ability to handle points (.) Files and file names with non-print characters. We continue to join some of the strange file names to the test directory, this script is always working very well. However, a guy uses it to measure an empty directory, this time * produces the output of "No Such File" (without this file). However, we can certainly continue to handle this situation ...

.... The uucp may be suspected of this email, it seems that I can only go here, please go to the rest of the bug.

Stephen

There is also a bigger question Stephen, didn't think of it, we have intended hidden from the beginning: UNIX file command does not work.

Date: Sat, 25 Apr 92 17:33:12 EDT Sender: Alan Bawden Topic: Simple Shell Programming (Simple Shell Program) Received: Unix-Haters

Oh! Don't be busy. Take a closer look. Do you really want to use the 'file' command? If you want to be happy, you can go to a UNIX machine right away, knock on the command "file *" in a directory with a variety of files.

For example, I run "file" in the directory of various C source code files - this is some results:

Arith.c: c Program Text

BINSHOW.C: C Program Text

Bintxt.c: c Program Text

It looks good. But this is not right:

Crc.c: ASCII text

have you seen it? 'file' is not determined by the suffix ".c", it uses some heuristics algorithm for the content of the file. Obviously CRC.c looks not so like C code - although it is for me.

GenCrc.c. ~ 4 ~: ASCII TEXT

GenCrc.c: c Program Text

It is estimated that I have made some modifications after Issue 4, so that GenCrc.c is more like C code ...

Tcfs.h. ~ 1 ~: c Program Text

TCFS.H: ASCII TEXT

It is clear that the TCFS.H after the first version is not too embossed is C code.

Time.h: 中文 t TEXT

That's right, Time.h looks more like English, not a general ASCII code. I don't know if 'file' can also judge Spanish or French. (By the way, your TEX document will be used as "ascii text" instead of "English text", but this is a bit running) Words.h. ~ 1 ~: ASCII TEXT

Words.h: english text

This may be because I have added some comments in Words.h after I first versions.

I will stay the most brilliant:

Arc.h: Shell Commands

Makefile: [NT] Roff, TBL, or EQN INPUT TEXT

I am wrong. I don't know what results will be used if they use these files based on the result of 'File'.

-Alan

Shell variable

Of course, Alan is still the most memorable, at least he has not tried the shell variable.

We have said before, SH and CSH have nothing to do with the SHELL variable. There is nothing, but some SHELL variables are semantically (such as the defined moments, change atomicity, etc.) is not well described or defined. I will always encounter some strange anti-conventional shell variables, only after repeated tests will be understood.

Date: THU, 14 Nov 1991 11:46:21 PST Sender: Stanley's Tool Works

Run this script:

#! / bin / cshunset fooif ($? foo) Henecho foo WAS unselse if ("$ foo" = "you Lose") Thenecho $ fooendif

Will produce the following error:

Foo: Undefined variable.

If you want this script to "work correctly", you have to help the following script:

#! / bin / cshunset fooif (! $? foo) Henecho foo WAS unsetset Fooelse IF ("$ foo" = "you lot") Thenecho $ fooendif

[Note that we must "set foo 'when you find that foo is not defined, is it clear?

Error code and error check

The example above did not point out how the file command returned to the script. In fact, it has not returned an error at all. The error is ignored. This is not because we are careless: many UNIX shell scripts (and other programs) ignore the error code returned by the calling program. This approach is desirable because there is no standard error code.

Perhaps the error code is extensively ignored, because these error codes are rarely displayed when the user knocks the command. Errors and error Checks are so rare in UNIX camps, so that some programs do not even have a refractory error.

Date: The, 6 Oct 92 08:44:17 PDT Sender: Bjorn Freeman-Benson Topic: It's always good news in Unix Land (good news in UNIX) Received: UNIX-HATERS

Take a look at this TAR program. And all UNIX "tools" (do not seem to be quite accurate), TAR's work is very strange and special. For example, TAR is an extremely optimistic program that does not have any bad things never returned to the wrong state. In fact, even if the error message is played on the screen, it is still "good news" (status 0). Run this script: Tar cf temp.tar no.such.file

IF ($ status == 0) Echo "Good news! no error."

You will get the following results:

TAR: no.such.file: no so file or directorygood news! no error.

I understand - I should not expect any consistency from the beginning, useful, help good, fast, and even correct results ...

Bjorn

OK, is it very cool by shell? Haven't I be addicted yet? Don't tighten, let's go back to a place, drilling into the UNIX sewer (PIPE) to experience endless pain and happiness

pipeline

UNIX is abused, welcome to UNIX sewer.

"In our century, Paris is still a mysterious place. If you know that you are a terrible Dashan, Paris will be uneasy." - Hugo "Tragic World"

Here is just my own view of Unix. About six years ago (when I have the first workstation), I used a lot of time to learn UNIX. It should be a good job. Fortunately, these garbage in the brain is slowly degraded over time. However, since this discussion begins, many UNIX supporters have sent me an example to "prove" Unix's power. These examples certainly evoke my many good memories: they all use a simple and useless feature.

There is a guy to say how a shell script allows him to get "success" (this script uses four noise the same command to rename all the '.pas' suffixes of the '.p' file ). But I still want to leave my religious enthusiasm to more important things than to change a few file names. Yes, this is the memory left to me: you use a lot of time to learn those who have a strange flower stand, but it is an empty. I still go to learn a useful trushy.

--Jim Gileeslos Alam National Laboratory

UNIX fans worshiped under the truth of the pipe (PIPE). They sing pipes: there is no Unix without pipelines. They are interspersed with sound: "Pipeline can make you construct more complex programs with simple programs. The pipeline can use the command in the way, and the pipeline makes it easier." Unfortunately, Yangge's role of the song It is not much better than the great flag.

The pipe is not a place. Modularity and abstraction is necessary in complex systems, which is the basic principles of computer science. The more excellent basic tools are excellent, and the complex system established by it will be more successful, the higher the maintenanceability. The pipe is still valuable as a structural tool.

The following is an example of a pipe:

EGREP '^ TO: | ^ cc:' / var / spool / mail / $ user | /

Cut-C5- | /

AWK '{for (i = 1; i <= nf; i ) Print $ I}' | /

SED 'S /, / / ​​G' | GREP -V $ USER | SORT | UNIQ

Will you understand? This program receives the user's mail list (almost what this means) is located by reading the user's mailbox. Like the water pipe in your home, this Unix pipeline will be mysteriously ruptured in a particular situation.

The pipe is sometimes very useful, but it performs inter-process communication by connecting standard input and output, this mechanism limits its application. First, the information can only flow one-way. The process cannot communicate two-way communication through the pipeline. Second, the pipe does not support any form of abstraction. The sender and the receiver can only use character streams to transfer information. A slightly complicated object is not directly transmitted by the pipe, must be serialized as a character stream, and of course the receiver must re-assemble the resulting character stream. This means you can't transfer an object and to create a definition code for this object. You can't transfer the address space of the pointer to another process. You cannot transfer file handles or socket handles or file permissions properties. Risks who have been self-righteous, we think the correct model should be process calls (local or remote) to deliver the first class structure (this is the C language from the beginning Functional Composition.

Pipeline is good for simple tasks, such as text flow, but use it to build robust software, it is a bit stretched. For example, in an early test of the pipeline, how to use the pipeline to combine some small programs to form a spell checker. This is a classic that reflects the simplicity, but if it is really used to check the misspelling, it is worse.

The pipe is often able to reveal a small hand in the shell script. Programmers use it to achieve some simple and fragile solutions. This is because the pipeline makes the two programs have rely on relationships. If you modify a program's output format, you must simultaneously modify the input processing of another program.

Most programs are step-by-step: first develop a demand specification for the program, and then the internal gradual shape is gradually formed, and finally writes an output process function. The pipe does not put this set in the eyes: As long as someone put a half-life program in the pipeline, its output format is dead, no matter how inconsistent, not standard and inefficiencies, you can only recognize it.

The pipe is not the only choice for inter-program communication. Macintosh has no pipeline, our favorite UNIX propaganda manual is written like this:

However, Macintosh is used in a trivial model. The system is not dealing with the character stream. Data files have higher levels, always related to specific programs. When did you pass the output of a Mac program to another? (If you can find the pipeline, you can justify your luck), you must completely understand what you are doing. You can't get Macfoo and MacBar together. - From "UNIX Life" Libes and RESSLER

Yes, these poor MAC users. If you can't turn the character stream through the pipeline, how can they insert a picture of the painting program in the document? How can I insert a table document? How can I send this east to the West an email? How can I get seamlessly to browse and edit it seamlessly, and I will reply back? There is no pipeline, we can't imagine how this is what is done by Macintosh in the past decade.

What is the same when your UNIX workstation is the same as Macintosh? What is the software you can run on it on it? Different departments of the same company? Moreover, these software can communicate with each other. If UNIX really did this, it was because Mac software developers put their software into UNIX and hoped to let UNIX look like Mac.

The fundamental difference between UNIX and Macintosh operating systems is that UNIX is designed for pleased, and Mac is for users. (Windows is an accounting, but this is some of the questions).

Studies have shown that pipes and redirects are difficult to use, not because they are here, but due to their random and non-intuitive restrictions. UNIX's own document has long indicated that only UNIX's death party can experience the work of pipelines.

Date: Thu, 31 Jan 91 14:29:42 EST Sender: Jim Davis Recipient: UNIX-HATERS Topic: Expertise I read this morning " A article "Computer Operating System Professional Knowledge" is written by Stephanie M. Doane and other two authors. Guess what operating system they study? Doane has studied UNIX newbies, the knowledge and performance of our hands and experts, and below is some summary:

"Only experts can use UNIX unique features such as pipes and redirections to construct command combinations"

In other words, each new feature of UNIX (except for those who have been moving hard from other systems) is so weird, so that they must be able to master the same weird learning and practices.

"This finds some unexpectedly, because these are the basic functions of UNIX, and these features are involved in all primary courses"

She also quoted some articles of S. W. Draper, Draper believed:

"There is no Unix expert at all in the world. If the expert refers to some people, they have exhausted all the knowledge of a professional, no need to learn anything."

I can't agree with this point. There have been countless people have been "exhaust" on the journey of learning UNIX's various ridiculous technology.

Some programs are even full, and the pipelines and file redirects are treated:

Sender: Leigh L. Klotz Received: UNIX-HATERS Topic: | vs. <) Date: THU, 8 OCT 1992 11:37:14 PDT

Collard% xtpanel -file xtpanel.out <.loginunmatched bracesunmatched bracesunmatched braces3 unmatched Right Braces present

Collard% cat .login | xtpanel -file xtpanel.outcollard%

You should ponder it yourself.

Find

Unix is ​​the most horrible, no matter how many scoops you have been driven by it, you can't lose consciousness. It's so open, it's endless.

--Patrick Sobalvarro

Lost in a huge file system is a common thing (imagine the needle needle needle). This problem has also encountered such problems due to the appearance of greater cheaper disks, PC and Apple users have encountered such problems. In order to solve this problem, the system often provides a search program, which is filed according to various conditions (such as file name, type, creation time, etc.). Both Apple Macintosh and Microsoft Windows provide powerful, convenient, and stable file search programs. The design of these search procedures takes into account user habits and modern networks. The Unix search program Find is not a user, but a CPIO, a UNIX backup tool. Find has not foreseen the existence of the network and the new features of the file system (such as symbolic links), even if it has undergone repetitive modifications, it still can't work well. Thus, although it is very significant for the user's meaning of the lost document, Find still does not stabilize and work.

The author of UNIX efforts is Find to keep up with the development of the rest of the system, but this is not easy. Today's Find has a variety of special options to process NFS file systems, symbolic links, execute programs, interactive execution programs, and even file the found file directly using the CPIO or CPIO-C format. Sun has modified Find and adds a background program to establish an index database for each file on the system. Due to some strange reasons, this database is used to search if you do not add any parameters to perform "Find FileName". Safe, is it?) Even if there is so much repair replenishment, Find still does not work properly. For example, CSH sees the symbolic link to go, but Find will not: CSH is written by the guys of Berkeley (the origin of symbolic link), but Find is from the original era of AT & T. In this way, the cultural differences between the Eastern and West have collided, causing huge confusion:

Date: Thu, 28 Jun 1990 18:14 EDT sender: pgs@crl.dec.com Theme: More Things to Hate About UNIX (More Reasons for That, Just in Unix) Received: Unix-Hate

This is my favorite. I work in a directory and want to use Find to find files in another directory, I do this:

PO> PWD / ATH / U1 / PGSPO> Find ~ Halstead -Name "* .trace" -printpo>

It seems that I didn't find it. But don't be busy, look at this:

PO> CD ~ Halseadpo> Find. -Name "* .trace" -print ../ Learnx / Fib-3.trace ../ Learnx / P20xp20.trace ../ Learnx / Fib-3i.trace ../ Learnx / FIB-5.TRACE ../ Learnx / P10xp10.tracepo>

Hey there! The file is there! Next time, if you want to find a file, remember that random to each directory, can you hide it there? UNIX this waste.

The poor Halstead comrades / etc / passwd record must be used to use a symbolic link to point to the real directory, so there is a command work, some don't work.

Why not change Find, let it link in a symbol? This is because any symbolic link to the high-level directory will introduce Find into the dead cycle. To handle this situation requires careful design and careful implementation to ensure that the system will not repeat the same directory. Unix uses the simplest approach: Sorry does not process symbolic links, let users look at themselves.

The networked system becomes more complicated, and the problem is increasingly difficult to solve:

Date: WED, 2 Jan 1991 16:14:27 PST Sender: Ken Harrenstien Topic: why find doesn't Find Anything (why do Find can't find?) Received: UNIX -Haters

I just found why "Find" no longer worked.

Although "Find" syntax is very disgusting, I am still barely use it, so as not to use a few small bubbles in a list of files in the maze.

In this brave new world with NFS and symbolic links, "Find" is useless. The so-called file system here is a group of messy numbers, "find", which does not want to deal with many file servers and symbolic links, and even the options are not available ... The result is that a large number of search paths are ignored by no sound. . I noticed this, it was a result of searching when searching in a big directory, and finally found because the directory is a symbolic link. I don't want yourself to check each search directory handed over to find - this fuck should be the work of find. I don't want to go to the system software every time this kind of situation occurs. I don't want to waste time to fight with Sun or the entire UNIX party. I don't want to use UNIX. Hate, hate, hate, hate, hate, hate, hate, hate.

--Ken (feel better, but still a little annoyed)

If you want to write a complicated shell script to process the files found, the result is often very strange. This is the tragic consequence of the shell pass parameters.

Date: SAT, 12 DEC 92 01:15:52 PST Sender: Jamie Zawinski Topic: Q: What's the oppositive of 'Find?' A: 'Lose' (Question: 'Find' antonym What? Answer: Lost) Receive: Unix-Haters

I want to find out all of the .el files existing in a directory .elc file. This should be less difficult, I use Find.

But I am wrong.

I will do this first:

% Find. -Name '* .el' -exec 'Test -f {} C'find: Incomplete Statement

Oh, I remember, it needs a semicolon.

% Find. -Name '* .el' -EXEC 'TEST -F {} c' /; find: can't execute test -f {} C: No Such file or directory

I really have you, I didn't go to parse this command.

% Find. -Name '* .el' -EXEC TEST -F {} C /;

咦, it seems that there is no done ...

% Find. -Name '* .el' -exec echo test -f {} c /; test -f ctest -f ctest -f ctest -f c ....

understood. It is the shell to put the braces.

% Find. -Name '* .el' -exec test -f '{}' c /; test -f {} ctest -f {} ctest -f {} ctest -f {} C

Ok? Maybe I mean the wrong, {} is not a symbol of the "replaced this file name" used by Find. Really? ...

% Find. -Name '* .el' / -exec test -f '{}' c /; test -f ./bytecomp/bytecomp-runtime.el ctest -f ./bytecomp/disass.el ctest -f. / Bytecomp / bytecomp.el ctest -f ./bytecomp/byte-optimize.el c ....

Oh, it turns out. What should I do now? I think, I seem to try "SED ..."

But I forgot a deep philosophy: "When I encounter a UNIX problem, some people will think 'I understand, I can try Sed.' This is two questions to deal with it." Test five I read the SED manual twice, I got this:

% echo foo.el | SED 'S / $ / C /'

then:

% Find. -Name '* .el' / -exec echo test -f `echo '{}' / | sed 's / $ / c'` /; test -f ctest -f ctest -f c ....

OK, it seems that I can only try all the combination of shell references, will there be one and me?

% Find. -Name '* .el' / -exec echo test -f "` echo '{}' / | s / $ / c'` "/; variable syntax.% find. -name '* .l '/ -exec echo test -f' `echo" {} "/ | SED" S / $ / c "` '/; test -f `echo" {} | SED "S / $ / c" `test - F `echo" {} "| SED" S / $ / C "` test -f `echo" {} "| SED" S / $ / C "` ...

Hi, the last thing seems to have a play. I just need to do this:

% Find. -Name '* .el' / -exec echo test -f '`echo {} / | SED" S / $ / c "`' /; test -f `echo {} | SED" S / $ / C "` test -f `echo {} | SED" S / $ / c "` Test -f `echo {} | SED" S / $ / C "` ...

Don't worry, this is what I want, but why don't you replace {} to file name? You carefully, {} is not a space in both sides? What do you want?

Oh, wait. The reference between the anti-single quotation is used as an element.

Maybe I can filter out this back single quotes with SED. Well, no play.

So I used it for half a minute to run "-EXEC SH -C ..." and finally appeared, and I wrote a piece of Emcas-Lisp code to do this. This is not difficult, very fast, and work.

I am so happy. I thought that everything passed.

I suddenly thought of another approach when I took a shower this morning. I tried it again and again, I deeply fell into her network, I liked a chaos, I couldn't extricate. drunk. Only Hanta's Scribe achieved the pleasure of me. I only tried 12 times to find a solution. For each traveled file, it generates only two processes. This is the way of UNIX!

% Find. -Name '* .el' -Print / | SED 'S / ^ / Foo - /' | / SED 'S / $ /; IF [! -f $ {foo} C]; THEN / ECHO / $ FOO; Fi / '| SH

Bwaaaahh Haaahh Haaahh Haaahh Haaah Haaahh !!!!

-Jamie

OK, playing in the sewer and hide and hide is quite interesting? Chapter 8 is over the laughter. When we go back, we will start programming, remember how the cute and charming nurse is talking to you when you are young. "Beef is not afraid, not hurting."

Chapter 9 Programming

"Beef is not afraid, not hurting."

Don't provoke Unix, it is weak, not moving, spitting the core (Core Dump)

--anonymous

If you learn programming by writing C code on UNIX, you may feel that this chapter has some awkward. Unfortunately, UNIX is so widely applied to the field of research and education, and few students can realize that many of UNIX is not reasonable.

For example, after listening to us about many languages ​​and the environment than C / UNIX, a UNIX enthusiast is such a defense for UNIX and C:

Date: 1991 Nov 9 Sender: TMB@ai.mit.edu (Thomas M. Breuel)

These languages ​​have indeed provide a powerful programming environment. But the UNIX kernel, shell and c language are more widely problematic, and these problems are not good at those languages ​​above (some are unable to handle).

These problem spaces include memory management and locality (implementation and termination in the process), persistent (use file storage data structure), parallelism (via pipeline, process and process communication Mechanism to achieve), protection and recovery (implementation by separate address space), and data expressions that can be visually read (implemented using text files). From a practical perspective, UNIX can deal with these issues very well.

Thomas Breuel praises UNIX to solve complex computer science issues. Fortunately, this is not a method for solving problems in other scientific fields.

Date: Tue, 12 Nov 91 11:36:04 -0500 Sender: Markf@altdorf.ai.mit.edu Record: UNIX-HATERS Topic: Random Unix Similes (Random UNIX Smiley)

Memory management is performed by controlling the generation and termination of the process, which is like dealing with the disease by controlling the life and death of the person - this ignores the true problem.

Getting continuity through UNIX files is like putting all your clothes, fantasy can find clothes from inside (unfortunately, I am doing this).

Conveying by pipelines, processes, and process communication mechanisms? The cost of UNIX processes is so high, so that it is not worthy. As is an encouragement of employees to have a baby to solve the problem of the company's human resources shortage.

Nice, UNIX can of course handle text. He also handles text. Well, there are, have I mentioned that UNIX handles text well?

--Mark

Spectacular UNIX programming environment

UNIX frenzy molecules are always promoting the so-called "programming environment" of UNIX. They say UNIX provides a wealth of tools that make programming work easier. This is the statement of Kernighan and Mashey in the "UNIX programming environment":

The Unix environment can improve programming efficiency, which is attributed to many small and useful programs - tools, which help from daily programming work. These procedures listed below are considered to be the most useful. We will explain other views as described below.

WC Files - The number of lines, words, and characters in the statistics file. Pr FILES - Print files, support the title and multi-collapse. LPR Files - Print file Grep Pattern Files - Find file rows that match some mode.

Many programmers work is done with them and some other related procedures. E.g:

Wc * .c

Used to make code quantity statistics for all C source code file; GREP GOTO * .C

Used to find all GOTO statements.

These are "most useful"? ! ? !

Reason. This is the daily work of the programmer. In fact, today I have used a lot of time to count my C code quantity, so that there is not much time to do other things. Wait a minute, I think I have to have a few more.

There is also an article on the same period "IEEE computer", which is the "Interlis Programming Environment" written by Warren TEITELMAN and LARRY MASINTER. Interlisp is an extremely complex programming environment. In 1981 InterlisP has a UNIX programmer to 1984 still in the dream.

The designers of the InterlisP environment are completely different. They decided to develop a complex tool that takes a lot of time to master, and the advantage is once learned, greatly improves programming efficiency. Listening to some truth.

Sadly, very few programmers can experience the use of such environments today.

Programming in the cave of Plato

I always have a feeling, the goal of computer language design and tool development should increase programming efficiency rather than decrease.

- a post oncomp.lang.c

Other industries other than computers have long realized the meaning of automation. When people walk into the fast food point, they need a consistent standard thing, not what French big dishes. A large-scale providing general food, which makes more money than small batches of cultivation.

- NetNews Reply

UNIX is not the best software environment in the world - it is not even a good environment. Unix programming tools are simple and difficult; UNIX debuggers and PCs can not be better; the parser (interpreters) is still rich toys; a change log and review (Audit TRAIL) always thinks Go do. Unix is ​​still treated as a programmer's dream. Perhaps it can only make programmers dream of efficiency, rather than really improving efficiency.

UNIX programmers have a bit like mathematicians. You can observe a mystery from them, and we call "Programming By Impens). Once we chat with a UNIX programmer, talk about the problem that needs such a tool, can answer questions such as "function foo call?" Or "that function changed the global variable bar". He also believes that this tool will be useful, proposal, "You can write one yourself."

Fairness said that he just said, "You can write a" instead of truly write one, this is because some of the characteristics of the C language and the strong link to the UNIX "programming environment", making it difficult to write such a program.

Parsing with yacc using YACC

"YACC" is that I used YACC (1).

--anonymous

"YACC" is the meaning of the compiler of the compiler. "YET Another Compiler. It accepts the syntax of context-free, constructs a PushDown Automaton for parsing. Run this automation, you get a parser for a particular language. This theory is very mature, because an important issue of computer science is how to reduce the time to write compilers.

This method has a small problem: many language syntax is not unrelated to the context. Such YACC's users have to add relevant code to each state conversion point to handle and context (type checking is generally handled). Many C compilers are used by YACC generated parsers; GCC 2.1 YACC syntax has more 1650 lines (if not Yacc, GCC should be a good work for free software foundation). The code generated by YACC is more.

Some programming languages ​​are more likely to analyze. For example, LISP can parse with a recursive drop parser. "Recursive decline" is a computer term, meaning is "Drinking Coca-Cola" can be realized. " As a test, we wrote a LISP recursive drop parser and only used 250 line C code. If it is written with Lisp, then a page paper can not be used. The computer science mentioned above, the editor of this book has not been born yet. The computer room is the world of dinosaurs, "real people" programmed in the dashboard. Today, sociologists and historical workers want to break their heads and can't understand why inexpected programmers are designed, realized and spreading so hard to analyze. Perhaps they will always need a difficult research project, designing a language that is difficult to analyze seems to be a good topic.

I always want to know what medicine they eat in that era.

The tool mentioned above is similar to the front end of a C compiler. The front end of the C compiler is an extremely complex thing, which is the complex syntax of C and the use of YACC. No one truly handles a tool, what is the strange thing?

Dead unix molecules will say that you don't need such a program, because there is GREP enough. Moreover, you can also use GREP in the shell pipe. One day, we wanted to find all where all the MIN functions in the BSD kernel source code. This is one of the results:

% Grep min netinet / ip_icmp.cicmplen = oiplen min (8, oip-> ip_len); * that not corrupted and of at least minimum length * If the incoming packet was addressed directly to us, * to the incoming interface *.. Retrieve Any Source Routing from the incoming packet;%

Very good, GREP found all MIN function calls, but not there.

"I don't know how to make love. I withdraw." ("Don't know how to make love. Stop.")

The ideal programming tool should be like this, which allows simple questions to be simple, allowing complex issues to be solved. Unfortunately, many UNIX tools pursue versatility, and ignored simplicity.

Make is a typical. From abstract sense, the input of Make is a description of the relationship. Each node on the relying on the map corresponds to this set of commands, which will be executed when the node expires (determined by the node it rely on). Nodes and files are related, the modification time of the file determines if the node has expired. Here is a simple relying on the relationship, that is, makefile:

Program: Source1.o Source2.occ -o Program Source1.o Source2.o

Source1.o: Source1.ccc -c Source1.c

Source2.o: Source2.ccc -c Source2.c

Here Program, Source1.o, Source2.o, Source1.c, Source2.c are nodes on the relationship diagram. Node Program relies on Source1.o and Source2.o.

If Source1.o or Source2.o is more than program, Make will run the cc -o program source1.o source2.o to regenerate Program. Of course, if Source1.c is modified, Source1.o and Program are outdated, so Make will re-compile and link.

Although Make's model is very universal, unfortunately designers have never considered simplicity. However, many UNIX newers can experience how simply "diamond" (Screw).

Continue us to the above example, assume that there is a programmer Dennis to debug Source1.c, so compile to use the debug option. He has revised Makefile: Program: Source1.o Source2.occ -o Program Source1.o Source2.o

# I'm debugging source1.csource1.o: Source1.ccc -c Source1.csource2.o: Source2.ccc -c Source2.c

The line of "#" is comment, it will be ignored by Make. Poor Dennis has run Make, this is it getting:

Make: Makefile: Must Be a Speparator on line 4.stop

Make happened. Dennis stared at Makefile and saw a few minutes, I saw it for a few hours, or I still don't understand anything wrong. He feels that the problem of notes, can not be very sure.

When he joined the comment line, he accidentally knocked into a space before the table started in the second line. Tabs is an important part of the Makefile syntax. All command lines (rows that CC in Example) must be headed by tab. This is the reason why Dennis's makefile does not work.

"What is it?" You may say, "Is this wrong?"

It is nothing wrong with it. However, if you want to work in other UNIX programming tools, you will feel that the table syntax is like the hair silk thunder in the "landmine", it looks like a Ma Pingchuan, step on it.

You know that tasting, space characters and newline characters are generally collectively referred to as "white characters" (WhiteSpaceChacters). "White Characters" means "You can feel boldly ignored" Many programs are doing this, and the spaces and tab are toned. As soon as Make is lonely, you will be drunk, and you are drunk. So our Dennis brothers may only give their own head to a shot, say goodbye to this tragic UNIX world.

Poor Dennis eventually did not find the Makefile's problem, he is now able to maintain a SENDMAIL configuration file for a central Western State University. Three minutes.

head File

The C language has something called head file, which is some explanation information, used by the source file when compiling. Like other functions on UNIX, if there is only one two, you can work very well, there will be no more play.

To know your source file, this is not easy. The header file is the C predessor loaded according to the #include instruction (Directive). This instruction has two usage:

#include

with

#include "header2.h"

The difference between the two usage and the implementation of each C pre-regulator, that is, any implementation can sprinkle with the child.

Let's take a look at Dennis's friends Joey, Joey is also a unix newbie. Joey has a C program foo.c, using some of the data structures defined in foo.h, foo.c and foo.h are placed in the same directory. You may already know "foo" is the name commonly used by programmers. The system programmer on the Joey machine also made a foo.h file and put it in the default system header file directory / usr / include

Upperfill Joey compiled foo.c to get a bunch of syntax errors. He is confused, the compiler always has an error in some of the data structures he defined, but these data structures are defined in foo.h.

You and I estimate where Joey's problem is, he must be such a header file:

#include

Not written:

#include "foo.h"

Joey doesn't know this. Maybe he is indeed a quotation method, but his compiler's lookup method is somewhat special. Anyway, Joey is killed, it is very innocent. Maintaining a lot of headers is a very headache, unfortunately, if you write a useful point C procedure, this is inevitable. Header files generally define data structures, one header is often dependent on other one-head file. To put the reliance relationship of those headers, you can't do this.

Of course, the compiler will help you. If you make a mistake, the compiler will not be in love with the syntax error. Remember, the compiler is a very busy program that does not have time to distinguish between undefined data structures and input errors. In fact, even if you just forget to knock a semicolon, the C compiler will also be angry, and the horse is not dry.

In the compiler community, this phenomenon is called "error avalanche", or according to the compiler's own statement: "I finished, I can't come." The lack of the semicolon will completely fain the parser, . This parser is likely to be written with YACC, YACC's correct program (very few cases) is well processed, but let it generate healthy and fault-tolerated parsers, this is a bit of hard. . Experienced C programmers know that only the first parsing is meaningful.

Toolproof and MAN Manual

The UNIX tool is a self-contained; the command line parameters can be arbitrarily explained. Such freedom is some annoying; don't think that I will learn a set of command line rules, you have to go, you have to read the MAN manual for each command to know how to use it.

I know that there is so much clear MAN manual for you to refer, you must be very happy.

Look at the following example. The "Summary" column is quite good, isn't it?

LS (1) UNIX programmer manual LS (1)

Name LS - List the contents of the directory

Summary LS [-ACDFGILQRSTU1ACLFR] Name ...

Description For each directory parameter, LS lists the contents of that directory; for each file parameter, LS gives the file name, and other information required. By default, the output will be arranged in alphabetical order. If there is no parameters, the contents of the current directory are listed. If there is a not only one parameter, these parameters will first be sorted properly, but the file parameters will always be ranked in front of the directory parameters.

Ls have many options:

[...]

The newline characters in the BUGS file name will be printed by printing characters.

Output equipment will be assumed to have 80 columns wide

The output will vary depending on the output device, such as the result of "LS -S" and the result of "LS -S | LPR". This is incorrect, but if you don't do this, some of the old shell scripts that depend on this feature will be finished.

If you want to play a game, let's read the BUGS section of each MAN manual, then imagine how each bug is caused. Look at this SHELL MAN manual:

SH (1) UNIX programmer manual SH (1)

Name Sh, For, Case, IF, While,:,., Break, Continue, CD, Eval, Exec, Exit, Export, Login, Read, Readonly, SET, SHIFT, TIMES, TRADONLY, SET, SHIFT, TIMES, TRAP, UMASK, WAIT - Command Language

Abstract ls [-ceiknrstuvx] [parameter] ...

Description SH is a command language that executes commands from terminals or files. Below is an explanation of each option.

[...]

Bugs

If you use the reference to the << provided to the input of the Non-synchronization using & running, the shell will not know the name of the document. Will generate a junk file / tmp / sh *, shell complains that you can't find a document with another name.

We used a few minutes and didn't understand what this bug is fucking. A UNIX expert said, "I scratched my head and wrote this BUGS, I was estimated enough to change this hanging stuff." Unfortunately, the modification of BUG is almost impossible, because it Will bring the soil of each newly released operating system. In the early 1980s, the BBN programmers really modified this tab bug in BBN. This is not very difficult, that is, a few lines of code.

Like all responsible citizens, BBN's hackers sent patch to Berkeley, hoping to add it into the main Unix code. After a year, Berkeley issued a new version of UNIX, Make's bug or existence. The BBN's hacker made a revision, and the patch was handed over to Berkeley.

.... However, Berkeley's third release is still old, and BBN's programmer is completely disappointed. They did not submit their patch, but replaced the trunk of the makefile in the Makefile to the tab. After all, the BBN hires them to write new programs, rather than repeatedly modify the same bug.

(It is said that the STU Felman (the author of Make) will explain this issue, he has not changed, because 10 users have started to be used at that time.)

The source code is a document. Wow ~~ 牛 逼!

If I write it is not easy, then you should not be easy.

- a UNIX programmer

We mentioned in the "Document" chapter that UNIX programmers believe that the source code of the operating system is the best document. A famous Unix historian once pointed out: "After all, the operating system is also reading the source code to know the next step."

However, by reading the source code, I understand Unix, which is like the classmates of Ken Thompson (right, that is, the big red question mark).

UNIX kernel source (more accurately, the code of Berkeley Network Tape 2) released on ftp.uu.Net) Berkeley Network Tape 2 is almost no comment, full of "paragraph" without the code, Goto can see everywhere, rack your brain Try to read people to make trouble. There is a hacker to be sigh: "Read the Unix code, just like walking in the alley of the five fingers. I always stop touched the pocket. I returned a voice in my mind 'old day, I will be robbed.'"

Of course, the kernel code has its own alarm system. This little annotation is spread around:

/ * Xxx * /

It means that something is not too strong. You should know where there is something.

This is absolutely impossible to be bug, my makefile needs it!

The programmer of BBN should be an alternative. Most UNIX programmers do not modify the bug: they don't have source code. Even if you modify it, it is not necessary. That's why UNIX programmers encountered the first reaction of bugs not repair it, but bypass it.

So we saw the tragic scene: Why don't you solve the problem in all, but a mistake? Perhaps the early UNIX programmer is the believers of Nietzsche's "eternal reincarnation" thought.

For debugging methods, there are two distinct factions: one is a "surgical part", including popular early ITS and LISP systems, and the program is always debugger participation during the operation, if the program crashes, the debugger (that is The so-called surgical doctors will diagnose treatment for problems.

UNIX is an older "corpse anatomy". If a program crashes in Unix, you will leave a Core file, from all aspects, this is no different from the body. UNIX debugger then identifies death. Interestingly, UNIX procedures are often the same as those, died of the disease, accidents, and negligence.

Deal with Core

If your program is spit (Core), you first have to do it. This should not be too difficult because the core file is always large - 4, 8, and even 12 megabytes.

The reason why the core file is so big because it includes all information used to debug: stack, data, code pointer, etc., all package, in addition to the dynamic state of the program. If you are debugging a web program, when your program spits, it is too late; the network connection of the program is no longer, and the more deadly hit is that all open files are now closed. Unfortunately, it can only be the case on UNIX.

For example, you cannot use the debugger as a command parser, or give the control to the debugger when the kernel is abnormal. If you want the debugger to take over when the program crashes, you can only run all programs in the debugger (yes, some UNIX version let you take over a running process with the debugger, but you must have a hand on your hand. Symbolic program files). If you want to debug interrupt code, your debugger must intercept each interrupt and then return the appropriate interrupt to the program. Can you imagine how three process switches occur in Emacs? Obviously, routine debugging ideas and UNIX philosophy are incorporated.

Date: WED, 2 Jan 91 07:42:04 PST Sender: Michael Tiemann Recident: UNIX-HATERS topic: Debuggers (Debugger)

Want to have a UNIX debugger so your feet? This is because if it wants to provide anything, it will follow a bunch, if there is a bug, it will vomit (dump core), if it spits, the core file you use to debug, you will Covered. If you can make the program to control how to spit the nucleus, when to spit the nuclear, and where to spit, it is too good.

BUG urn

Unlike other operating systems, UNIX offers bugs as standard operations. The reason why many unix bugs can't get amendment, there is a reason why you don't speaking - if you fix it, some programs will die. However, ridiculous is that UNIX programmers have never considered downward compatibility when adding new features.

Considering these, Michael Tiemann gives 10 reasons for the UNIX debugger overwrites the Core file:

Date: THU, 17 Jan 91 10:28:11 PST Sender: Michael Tiemann Received: UNIX-HATERS Topic: Unix Debuggers (UNIX Debugger)

The 10 best reasons for David Letterman (American Famous Night Drop Show) are:

10. This will destroy the already code. 9. This requires a modification of the document. 8. It is too difficult to implement. 7. How is this ambugger? Why don't you write a "tool" to do it? 6. If the debugger spits the core, you should drop your own program and start the debug adjustment. 5. It is difficult to understand. 4. Where is the biscuit? 3. Why don't you do it now? 2. Unix is ​​not a god. Where is any problem?

UNIX programmers always fight the scorpion of "this will destroy the code", and do not want to correct the bug. It can be inside this, and the revised BUG will not only destroy the existing code, but also to modify the simple and perfect UNIX interface, which is the life of UNIX presence. As for this interface, it is not important. Unix people don't propose better interfaces, don't correct bugs, but sing "Unix interface is simple, good. Theunix interface is beautiful, it is beautiful! Unix is ​​not guilty! Unix is ​​reasonable!".

Unfortunately, bypassing bug is a very bad behavior that makes errors become part of the operating system specification. The more you wait, the more difficult to correct it, because more and more procedures will try to bypass Bug, so that there is no BUG can't live. Similarly, modify the impact of the operating system interface, because more programs must be modified according to this correct new interface. (This explains why LS has so many options to complete almost the same job). If you still get a frog to boiling water, it will jump immediately. It knows that boiling water is hot. However, if you put the frog in the cold water, slowly heat, the frog does not feel anything until it is last burned.

UNIX interface has been opened. Previously, all interfaces of the input / output only include Open, Close, Read and Write. Network support has added a big house to UNIX. Now, there are at least five ways to input data to a file handle: Write, Writev, Send, Sendto and SendMsg. Each has different implementations in the kernel, which means that there is five times that may have bugs, and five different performance results need to be considered. Reading the file is also the same (READ, RECV, Recvfrom, and Recvmsg). Waiting for death, frogs.

File name extension

There is an exception to the provisions of UNIX "All Programs Self-integrated". UNIX programs often handle one or more files. UNIX Shells provides a method of named a file, and the shell will expand this set of files to each command as a file list.

For example, suppose you have files A, B, and C in your directory. If you delete all of these files, you can run RM *. Shell will extend "*" into "A b C" and pass them as RM parameters to it. This method has many problems, which has been mentioned in the previous chapter. However, you should know that let the shell to extend the file name: but the result of a well-designed design. In the article published by Kernighan and Mashey (IEEE computer magazine, April 1981), they pointed out: "Take this as a mechanism of shell, which avoids repetitive labor of each program, but also guarantees all The program provides consistent input. "An ideal for Unix is ​​to let anyone can run any shell. Now you can't run any shell; your shell must provide a file name extension).

Don't be busy. Standard input / output library (Unix so-called STDIO) does not "provide consistent input for all programs"? A library function that is provided for extending file names is not going? Does these guys have heard of the link library? Those statements about performance are also nonsense, because they can't provide any performance data, they don't even explain what "performance indicators" is. What is the development of a small program? Or refers to high performance all the files all the files.

In most cases, let Shell's file name extension does not matter, because this is nothing different from the results of the program their own expansion. However, like many gates on UNIX, it will bite you sooner or not.

Suppose you are a unix newbie, there are two files A.M and B.M in the directory. You are used to MS-DOS, want to change their names into A.c and B.c. Well ~~ I didn't find the rename command, but the mv command seems to be almost. So you execute mv * .m * .c. The shell extends this command to MV A.M B.M, and your hard work has worked hard for a few hours of B.M.

Think about this question, you will find that you can't provide a function as the MS-DOS "Rename" in theory. For software tools, do so much.

Quality, or "all input lines must be less than 80 characters"

"ACM Communication" in November 1990, a brilliant article written by Miller Fredriksen et al., The topic is the "empirical study of the stability of UNIX tools". They use some random data as the input of UNIX tools, found 24-33% (different UNIX issues varying) tools to collapse. Sometimes even the whole system is over. The article is starting with a joke. One of the authors used a very poor telephone connection to find that many tools were collapsed. So he decided to conduct more systematic investigations for this phenomenon.

Many bugs can be attributed to the C language as a rules. In fact, many of UNIX is caused by C language in brain damage. The core of UNIX and all the tools are written in C language. The famous linguist Benjamin Whorf said: the language determines the idea. UNIX has deep C. The C language makes the programmer at all imagine how to write a robust program.

The C language is extremely small. It is designed to compile quickly on various hardware, so it has a similar structure with hardware.

At the beginning of UNIX, the use of advanced language to write an operating system is a revolutionary idea. Now you should consider using a language with an error check.

C is the most underlying language, born in the hardware's more underlying era. PDP-11 is not available, C language will not have. Over the past few decades of programming language research shows that the functions such as incorrect processing, automatic memory management, and abstract data types will make the developed program more robust. You can't find these things in C. The C language is too popular, no one will consider adding functions such as data tag or hardware garbage collection support. Even if the hardware provides garbage collection function, it is only a lot of silicon wafers because many C language written is unable to use it.

Recall that C is unable to handle an integer overflow. The solution is to use the integer size that exceeds the problem, I hope this size is enough for you.

C also does not have a true array. It has something like an array. It is actually a pointer to a memory. Array Location Expression (Array [Index]) is just a short- of expressions (* (array index)). So you can even say index [array], this is a meaning of expression (* (array index)). Smart? This usage can often be seen when character processing. Array variables and pointer variables can often be interchangeable.

For example, suppose you have:

Char * str = "bugy";

Then the following statements are the same:

0 [Str] == 'b' * (STR 1) == 'u' * (2 Str) == 'G'str [3] ==' Y '

C language is great enough?

The problem with this approach is that C does not do any automatic array boundary check at all. Why is this C do it? The array is just a pointer in C, you can point the pointer to any place, is it? However, you don't want to write doodles in memory, especially in some critical places, such as the stack of programs.

This introduced us to a class of bugs mentioned in Miller's articles. Many programs crash when reading a character buffer on the input to the stack. Many C programs do this; the following C program reads a line into a group on a stack, then call the DO_IT function to process.

A_Function () {Char C, Buff [80]; INT i = 0; while ((c = getchar ())! = '/ n') BUFF [i ] = C; buff [i] = '/ 000'; DO_IT (BUFF);

This type of code is stinking Unix. Know why the buffer is set to 80 characters? This is because many UNIX files have up to 80 characters per row. Know why there is no boundary check, no file tail check? This is because this programmer likes to embed the assignment statement such as c = getchar () into the While loop. Letter do not believe, some people also recommend this reduction in C, how can the fucking can readability. Finally, call the do_it (), the array is turned into a pointer as the first parameter. As an exercise: What is the result of this program if it reaches a file in a line?

When UNIX users feel about this built-in limit, they don't think of this bug, but try to escape it. For example, UNIX's Tape Archiver TAR cannot handle a path name of more than 100 characters (including directories). Workaround is: Do not back up your directory to tape, or use dump. A better way is: Don't build too deep catalogs, so that the absolute path of the file will not exceed 100 characters.

At 10:14:14:100 am, January 18, 207, 2007, UNIX Horse Tiger programming will stage a brilliant scene at this moment, then Unix's 32-bit TimeVal will deplete ...

Go back to us in front of us, assume that the input line has 85 characters. This function has no problem accepted this input, and it is the case where the last five characters will be put? The answer is that they will occupy any 5 bytes that are discharged behind the array. What is it in front of it?

Two variables of C and i may be assigned after an array of characters, so it is possible to be built by 85 characters long. If you enter 850 characters? The important C operation environment information information on the stack may be destroyed, such as returning an address, etc. The best result of destroying this information is that the program may crash.

We say "may crash" because the program's writer never thought that you can ruin the stack. Imagine that our program reads a long line, about 2,000 characters, this line character is used to cover the return address on the stack and other environmental information, which will call a piece of code buryed in 2,000 characters. This code may do some very useful things, such as execution (Exec), run a shell, run some commands.

Robert T. Morris's famous unix worm is used to use this mechanism (and some other techniques) black into UNIX host. I don't know why others will do this, I really don't know, hey.

Date: THU, 2 May 91 18:16:44 PDT Sender: Jim McDonald Received: UNIX-HATERS Topic: How many fingers on your hand? (How many fingers do you have?)

:( The following is a report for my boss:

A program for updating the Make file uses a pointer, destroying an array of relying on the relationship, which is used to generate makefile. Direct consequences are generated error Makefile can't be used to compile anything, there is no desired object file (.o), so compiling eventually failed. The day of work is so powerful, just because a fool thinks that 10 head files are enough to use, and then the extremely dangerous optimization of it is to generate all Make files in 1 millisecond!

The disadvantages of networked are, you can't dig up his heart again in someone's office.

(About stack overflow attack, refer to classic papers href = http: //www.phrack.org/phrack/49/p49-14>

Smashing The Stack for Fun and Profit --me)

Abnormal processing

The biggest challenge to prepare a robust program is how to handle errors and other exceptions. Unfortunately, C has almost no help. There are very few people who learn to be programmed today, who knows what is abnormal. An exception is a state generated when the function does not work properly. Exceptions often occur when requesting system services, such as allocating memory, open files, and more. Since C does not provide exception processing support, the programmer must add an exception handling code when the service request is requested.

For example, the following is a method recommended by using malloc () in all C language textbooks:

Struct BPT * Another_Function () {struct BPT * Result; Result = malloc (Struct Bpt)); if (Result == 0) {FPRINTF (stderr, "error: malloc: ??? / n"); / * Recover gracefully from the error * / [...] return 0;} / * do something interacting * / [...] returnrate;}

The Another_Function function assigned a structure of a type BPT and returned a pointer to this structure. This code illustrates how to assign memory to this structure. Because C does not have explicit abnormal processing support, C programmers must do this (that is, the code of bold).

Of course you can do it. Many C programmers believe that this is a small affairs, never doing an abnormal treatment. Their procedures are often like this:

Struct BPT * another_function () {struct bpt * result = malloc (sizeof (struct bpt)); / * do something interacting * / [...] return

How simple, how clean, most system service requests will succeed, is it? Such procedures are well operated in most cases until they are applied to complex and special places, often mysteriously.

The implementation of the LISP always includes an exception handling system. The abnormal conditions include the name of Out-of-memory, and programmers can provide exception handle functions for specific exceptions. These processing functions are automatically called when an exception occurs - the programmer does not need to intervene, nor does it need to be special inspections. Appropriate use can make the program more robust.

The programming language such as CLU also has built-in exception handling. Each function definition has a range of exception conditions that can be issued. Explicit support for exceptions can help the compiler to check those unreated exceptions. The CLU program is always very robust, because the compiler forces the CLU programmer to consider the abnormal handling problem. What is the C pro program?

Date: 16 DEC 88 16:12:13 GMT Topic: Re: GNU Emacs Sender: Debra@alice.ucp

<448@myab.se> Lars@myab.se (Lars Pensy)> Write: ... All programs should check the return results of the system call (such as Write), which is very important.

Again, unfortunately, very few programs do this when reading (Write).

UNIX Tools generally check the return value of the Open system call, assume that all subsequent Read, Write and Close will always succeed.

The reason is obvious: the programmer is very lazy, and the error handler will look smaller and faster. (So ​​your system has a more excellent performance performance).

The author of this letter continues to point out that due to most system tools do not check the return values ​​called by Write () and other systems, the system administrator must ensure that there is enough space at the time of the file system. Something: Many UNIX programs assume that they can write any successfully opened files, how much will you write?

Read here you may have frown, "Well ~~". The most terrible thing is that on the first few pages of the article "Experience in the Stability of UNIX Tools", it is reported in the previous few pages of this article, which shows how the Houston's outer space center is transformed into UNIX. systematic. "Well ~~" capture bug is the society can't receive.

Do not check and report BUG, ​​which makes the system produced by the manufacturer seem to be more robust and powerful. More importantly, if the UNIX system reports every error, then there will be no one to use it! This is a live reality.

Date: THU, 11 Jan 90 09:07:05 PST sender: daniel weise Record: UNIX-HATERS topic: now, isn't That clear? (Understate now?)

HP has done some work so that our HP UNIX system can report some network errors that may affect it. These HP systems and Sun, MIPS, and DEC workshops share a network. We often find problems caused by other machines, but when we notify those machine owners (because these systems do not report errors, they don't know that their machine has half time to use it on the retransmission of packets), they It is often referred to as the problem we here, because only us have reported the mistake here.

"The two countries fight, do not make", but in the UNIX world, you better don't make a letter.

Can't fix it? Restart!

If a key software does not properly handle the error data and operating conditions, how about the system administrator is good? Well ~~ If it can work properly in a period of time, you can run through it to restart it. This magazine is not very reliable, nor is it scalable, but it is enough to let Unix hard to write a while.

Here is such an example, explaining how to provide email services in the unstable NAMED program:

Date: 14 May 91 05:43:35 GMT Sender: Tytso@athena.mit.edu (Theodore Ts'o) (famous TED TS'O? --ME) Theme: Re: DNS Performance Metering: a wish list For Bind 4.8.4 (DNS Performance Test: Bind 4.8.4 expected menu) Received: Comp.Protocols.tcp-ip.Domains

We now solve this problem: I wrote a program called "Ninit" running Named in a DEAMON mode (Nofork), then waits to exit. When Named exits, Ninit restarts a new named. Also, every five minutes, Ninit will wake up once again send a SIGIOT signal, and the NAMED will package some status information written /usr/tmp/named.stats file after receiving this signal. Every 60 seconds, Ninit will use local NAMEDs to resolve the domain name. If there is no result in a short time, it will kill the named and restart a new one.

We run this program on the MIT's name server and our mail gateway (Mailhub). We found that it is useful and can capture the mysterious death or zombie of Named. This is indispensable at our mail gateway, because even if the domain name resolution interrupts a small meeting, our mail queue will also fry.

Of course, this type of approach will trigger such a question: What should I do if Ninit has bugs? Do you have to write a program to restart ninit? If you write, how do you guarantee that normal job?

This attitude towards software errors is very much. The following MAN manual has recently appeared on my table. We can't affirm that this is not a joke. Part of the BUGS is very surprising, because the bugs listed there are Unix programmers to never remove from the code: Nanny (8) UNIX programmer manual Nanny (8)

Nanny - nurse, running all services

Summary / etc / nanny [switch [argument]] [... switch [argument]]

Description Many systems provide users with a variety of service (Server) features. Unfortunately, these services often unclear strike, causing users to obtain the services they need. The role of nanny (nurse) is to look at these services, avoid the failure of key services without the need to monitor the system administrator.

In addition, many services use log files as output. These data are often full of disks. However, these data is an important tracking record, which should be saved as much as possible. Nanny will regularly redirect the log data to a new file. In this way, log data is completely completed, and the old log file can be arbitrarily transferred without the impact on the service. (Now this is the mission of logrotate - Me)

Finally, Nanny also provides some control functions that allow system administrators to run when Nanny and the services it look.

Option ...

BUGS has a service to separate Fork (Detaching fork) in Nanny. Nanny will mistakenly think that this service is dead, keep it back.

So far, Nanny cannot tolerate the error of the configuration file. If the path of the configuration file is not or wrong, Nanny will die.

Not all options are implemented.

The network function of the Nanny relies on the system for processes. If the network code is incorrect, Nanny will not process these errors, may be zombie or dead cycles.

For unstable software, it is often restarted, which has become the daily work of the Mit Athena, and now they will restart the AFS (Andrew File System, a Network File System) server at 4 am every Sunday. I hope that there is no one on weekends to keep the job next Monday ...

How, UNIX programming is fun? Thrust, excitement, happiness! It's time, take a break, marijuana is not strong, there is heaven, c is tired, we have C ! Rest assured, not far from death.

Chapter 10 C 90s COBOL

Q: What is the name of "C" and "C " coming? A: This is their grade

- Jerry Leichter

There is no more philosophical thoughts that are more than C more reflecting the philosophical idea of ​​"never give the user."

Object-oriented programming can be traced back to Simula language in the 1960s, which has developed greatly in SmallTalk language in the 1970s. Many books will tell you how object-oriented language can improve programming efficiency, make the code more robust, and reduce maintenance costs. But you want to get these in C .

This is because C does not understand the object-oriented substance. Non-but not simplified, but increase more complexity. Like UNIX, C has never been well designed, it is from one error to another, it is a piece of clothing. Even your own grammar is not strictly defined (no language dares this), so you can't even know that a line of code is not legal.

Make C to COBOL, in fact, it is the insult of COBOL. Under the technical conditions of that era, COBOL has made a very different contribution. If anyone has made something with C , it is very different. Fortunately, a lot of good programmers must try to avoid C damage, they only use C, and respect those who are ridiculous. Usually, this means they must write a non-faceted tool to get the features you want. Of course, their code will look extremely weird, lose compatibility, difficult to understand and reuse. However, as long as there is a little C taste, it is enough to convince the head to approve their projects. Many companies have been unproved by a chaotic COBOL code that has been chaotic in many years. Companies that turn to use C just realize that they are going. Of course, this is too late. The seeds of the software disaster have been broadcast, water fertilization, get careful care, waiting for more than ten years, he will grow into a big tree. Wait to see it!

Object-oriented assembly language

C has no characteristics of a high-level language. Why do you say that? Let us look at the high-level language should have those features:

Elegant: There is a simple and easy-to-understand relationship between the concepts and the concepts expressed: each expression of the high-level language represents only one concept. The concept can be independently expressed and the powerful use of powerful: High-level language can provide the programmer to describe the solution by providing a high-level language to any precise and complete program behavior. High-level procedures are easy to maintain because their purpose is very clear. According to a high-level program code, the modern compiler can generate efficient code for a variety of platforms, so the portability and reusability of high-level programs will naturally be strong.

Using a low-level language requires countless details to consider, most of them are something related to the internal operation of the machine, not the problem to solve itself. This is not only difficult to understand, but it is easy to obey. Now, it is necessary to update the system almost this year, and it will take high cost to modify low-level code or completely rewrite.

Sorry, your memory is leaking.

High-level language has built-in solutions for common problems. For example, well known memory management is wherever possible. Before using an object, you must allocate memory, appropriate initialization, carefully track usage, and release it correctly. Of course, everything is abnormal and it is easy to make mistakes, and a minimal error may lead to catastrophic consequences. Positioning and modifying such errors are difficult to distinguish because they are extremely sensitive to changes in configuration or use.

The structural pointer that is not assigned memory will cause the program to crash. The structure that is not properly initialized will also make your program crash, but it is not necessarily completed. If it is not possible to track the use of structures, it is likely that it is likely to release a piece of memory in use. Still crash. It is best to allocate some structures to track those structural objects. But if you are too conservative, you don't release those memory that is not very definitely not used, then you have to be careful. The memory will soon be full of unused objects until the memory is exhausted, the program crashes. This is the horror "memory leak".

What should I do if you have too much in memory space? The solution is to re-return the memory by moving objects, but there is no play in C - if you forget all references to update the object, then you will mess, the result is still crash.

Many real high-level languages ​​provide a solution - That is garbage collection (GARBAGE Collector). It records all objects, if the object will be recycled, never mistaken. If you use a language with garbage recycling, you will get a lot of benefits:

A large number of bugs have no trace. Is it very cool?

The code will become shorter read because it doesn't have to worry about the details of memory management. The code is more likely to run efficiently under different platforms and different configurations.

Hey, C users must do their own to pick garbage. Many of them were washed brains, think that this will be more efficient than the garbage collection tools provided by experts. If you want to create disk files, they are estimated that they will not use the file name, and more willing to deal with the track sector. Manual recycling garbage may be more efficient to one or two, but you certainly don't use word processing software.

You don't have to believe us here. You can read B. ZORN's "Consideration measurement of conservative garbage collection" (Colorado University Boulder Branch, Technical Report CU-CS-573-92), text-in-use C manually optimized garbage recovery technology and standard garbage collector Performance comparisons, the results show that the performance of the garbage collector written by C programmers should be different.

OK, suppose you are a buzzing C programmer, want to use garbage collection. You are not alone, many people think this is a good idea, decided to write one. God, guess how? You will find that there is no better garbage collection in other languages ​​in C . One reason is that (surprised!) The object in C is no longer an object after compiling and running. They are just a hexadecimal rotten mud. Without dynamic type information - garbage collector (also debugger) Can not know what objects in any memory, what is the type, and whether someone is using it at this time.

Another reason is that even if you can write a garbage collector, if you use the code that does not use garbage recycling function, you will still be broken. Because C has no standard garbage collector, it is very likely that there will never be. Suppose I wrote a database program that uses my garbage collection function, you wrote a window system that uses your own garbage reclaim function. But you close a window with my data record, your window will not inform my data record, tell it that no one has referenced it. This object will not be released until the memory is exhausted - the memory leaks, the old friend meet again.

Is it difficult to learn? now it's right

C and assembly language are very similar - it is difficult to study hard. If you want to learn, it is more difficult.

Date: MON, 8 APR 91 11:29:56 PDT Sender: Daniel Weise Recident: UNIX-HATERS Topic: from their cradle to our grave (from their cradle to our grave )

One reason that caused this fragile in the UNIX program is that the C programmer is educated from the enlightenment period. For example, the "C Programming Language" of Stroustrup (C ) is the first full program (that is, the one after the 300K "Hello World" program is an English / metric conversion program. The user uses the end "I" to indicate the infographic input, and the metric input is represented by the end "C". Below is an outline of this program, written in real UNIX / C:

#include

Main () {[Variable Declaration] CIN >> X >> CH ;;; A Design Abortion. ;; Read X, then read CH. IF (CH == 'I') [Handle "I" case] else if (ch == 'c') [handle "c" case] else IN = cm = 0 ;; Good, no reporting error . ;; Just do something.

Conversion]

Turn 13 (page 31), give an index range from N to M implementation examples (rather than from 0 to m). If the programmer uses an index of the range, this program is just a smile returns the first element of the array. Unix 's ultimate brain death. Syrup of Ipecac, a poison)

Syntactic Sugar is the culprit of the semicolon cancer.

--Alan perlis

All grammar errors that can be encountered in the C-programming language can almost be accepted by C , successfully compiled. Unfortunately, these grammatical errors do not always generate the correct code, because people are not perfect, they are always being knocking the wrong keyboard. C General can always compile these errors. C , otherwise, it makes you successfully through compilation, but if you really run, wait for a headache.

The syntax formation of C is also unblocked with its own development. C has never been designed: it is just gradually evolving. During the evolutionary process, some structures have caused the language of language. Special rules are used to solve these secondary sense, these difficult rules make C complex difficult to learn. So many programmers copy them on cards for from time to time, or they will not use these features at all.

For example, C has a rule that if a string can be parsed to a statement or a statement, it will be treated as a declaration. The parser expert sees this rule will often be cold, they know that it is difficult to implement it correctly. AT & T can even don't even For example, when Jim Roskind wants to understand the meaning of a structure (he feels that normal people will have different understandings for it), he wrote the test code and handed it over to the "CFRONT" compiler of AT & T. Cfront crashed.

In fact, if you download the open C syntax of Jim Roskind from Ics.uci.edu, you will find that C grammar2.0.tar.z in the ftp / pub directory: "Pay attention to my grammar and Cfront does not necessarily keep consistent, because a) I am consistent inside my syntax (this is from its normative and YACC's confirmation. B) Yacc generated parser does not spanning (this possibility). Many stinky eggs, but ... every time I want to know the syndrome of some structure, if ARM (Annotated C Reference Manual, with annotated C reference manual) is unclear, I will take Cfront to compile it, CFRONT is always vomiting (Core Dump) "

Date: Sun, 21 May 89 18:02:14 PDT Sender: Tiemann (Michael Tiemann) Received: SDM@cs.brown.edu Cc: UNIX-HATERS Topic: C Comments (C Note)

Date: 21 May 89 23:59:37 GMT Sender: SDM@cs.brown.edu (Scott Meyers) News Group: Comp.lang.c Organization: Brown University Computer

Take a look at this line C code:

// ****************************

How to handle it C compiler? The GNU G compiler believes this is a row of comments consisting of a bunch of stars (*), but the AT & T compiler think this is a slash plus a comment start (/ *). I want to know which one is correct parsing, but Stroustrup's book ("C Programming Language") can't find the answer.

In fact, if you use the -e option to compile, you will find the ghosts that predessor, my problem is: Is this AT & T pre-regulator bug? If not, why? If it is bug, will version 2.0 will be corrected? Still can still be so?

Is this the BUG of the GNU preprocessor? If so, why?

Scott Meyers

SDM@cs.brown.edu

There is an old rule in UNIX parsing, try to accept the longest syntax unit (TOKEN). This will not be seen as three variable names ('f', 'o' and 'o'), but only as a variable 'foo'. Look at this rule how useful in the following program (and what is the choice of '/ *' as the comment starting value):

Double QDIV (P, Q) Double * P, * q; {RETURN * P / * Q;}

Why is this rule not applied to C ? Very simple, this is a bug.

Michael

Worse still in the back, C biggest problem is that its code is difficult to read, even for people who use it every day. Take another programmer's C code to see, not licking. C no piece of taste is a messy ugly. C claims to be an object-oriented language, but does not want to bear any object-oriented responsibility. C believes that if any of the procedures are complex to need garbage recycling, dynamic loading, or other features, explain that he has enough ability to write one and have enough time to debug.

The powerful feature of the C operator overloading is that you can turn a clearly straight-white code to something comparable to the worst APL, ADA or FORTH code. Each C programmer can create a Dialect, and completely fell by other C programmers.

However - - Dialects in C or even standards are also private.

What is abstract?

You may think that C syntax is its worst part, but when you start to learn C , you will know that you are wrong. Once you start writing a formal large software with C , you will find that the abstract mechanism of C is rotten from the roots. Every computer science textbook will tell you this, abstract is a good design source.

The association of each part of the system will result in complexity. If you have a 100,000 row of programs, each line is related to the details of other line code, then you must take 10,000,000 different associations. Abstract can reduce this association by establishing a clear interface. A code that implements a function is hidden after the modular wall.

Class (Class) is the core of C , however the class is implemented but hinders the modularity of the program. The class has exposed so many internal implementations, so that the user has strongly relied on the specific implementation of the class. In many cases, do a little change for the class, you have to recompile all the code to use it, which often causes developmental stagnation. Your software will no longer "soft" and "plastic", and become a large piece of concrete.

You will have to put half the code in the header file to declare the class. Of course, the difference between the public / private provided by the class declaration is not used, because "private" information is placed in the header file, so it has become a public message. Once in the header file, you are not willing to modify it because it will cause annoying to compile. Programmers then use the repair mechanism to avoid modify the header file. Of course, there are other protection mechanisms, but they are like a reduction barrier, can be arbitrarily bypass by anxious guy. As long as all objects are converted (CAST), there is no hateful type check, this world is clean. Many of many languages ​​each provide a well-designed abstract mechanism. C throws some of these most important parts, and people are also confused for those provided. Have you encountered people who really like templates (Template)? The template makes the implementation of the class different from the context. Many important concepts cannot be expressed in this simple way; even if they are expressed, it will not be able to call it a direct name.

For example, namespace (Namespace) can avoid conflicts with the name of your code and other parts. A clothing manufacturing software may have an object called "Button", which may link with a user interface, and there is a class called "Button". If you use a name space, there will be no problem, because usage and each concept is clear, no ambiguity.

This is not the case in C . You can't guarantee that you will not use the names that have been defined elsewhere, which often leads to catastrophic consequences. Your only hope is to give the name, such as ZjxButton, and others will not use the same name.

Date: Fri, 18 Mar 94 10:52:58 PST Sender: Scott L. Burson Topic: Preprocessor (Preprocessor)

C language fans will tell you that the best function of C is the pre-processor. In fact, it may be the most feet. Many C processes consist of a bunch of spider web (if each UNIX can be compatible with each other, it is hard to make this). But this is just the beginning.

The biggest problem with the C pre-regulator is that it locks Unix lock in the text file, and then throws away the necklace. In addition to text files, C source code cannot be stored in any other way. why? Because the C code that is not preprocessed cannot be parsed. E.g:

#ifdef bsdint foo (#elsevoid foo () {# Endif / * ... * /}

Here the function foo has two different beginnings, depending on whether the macro 'BSD' is defined. Direct analysis is almost impossible (as we know, never achieved).

Why is this so disgust? Because this hinders us to add more intelligence for the programming environment. Many UNIX programmers have never seen such an environment, I don't know what I have been deprived. However, if you can automatically analyze the code, you can provide a lot of very useful features.

Let us look at an example. At the era of the C language, the preprocessor is considered to be unique to provide open code (Open-Coded, means that the code is embedded directly into the instruction stream instead of the function call). For each simple and common expression, open code is a very efficient technology. For example, a small function MIN can use macro implementation:

#define min (x, y) ((x) <(x): (y))

Suppose you want to write a tool to print a function in a program called MIN. It's hard to listen to it, is it? But if you don't resolve this program, you can't know the boundaries of the function. If you don't do the pre-processor, you will not be parsed, but once you have been preprocessing, all MIN will not exist! So, you can only use grep. There are other problems with the use of the preprocessor to implement open code. For example, you must pay attention to those excess parentheses in MIN macro. In fact, these parentheses are essential, otherwise, when MIN is started in another expression, the result may not be what you want. (Hope, these parentheses are not all necessary - as for those parentheses can be omitted, this is allowed to practice to the reader).

The MIN macro's most sinful problem is that although it is used as a function call, it is not a function. Look at this example:

A = min (b , c);

After the preprocessor has been replaced, it becomes:

A = ((b ) <(c)? (b ): (c))

If 'B' is less than 'c', 'b' will be added twice instead of once, the return will be the original value of 'b'.

If MIN is really a function, 'b' will only be increased once, and the return value will be the original value of 'b'.

C For C, it is like lung cancer for lung

"If the C language gives you enough rope to hang yourself, then C gives the rope in addition to your neighbors, and provides a rope needed for a sailboat."

--anonymous

Sadly, learning C has become the most profitable investment of each computer scientist and serious procedures. It rapidly became an essential row in your resume. In the past this year, we have seen a lot of C programmers, they can write a good code with C , but ...

... they hampe it.

Programmer's evolutionary history

middle School High School

10 Print "Hello World" 20 End

College freshman

Program Hello (Input, Output); Begin Writeln ('Hello World'); END.

University fourth grade

(Defun Hello () (Print (List 'Hello' World)))

Just participated in work

#include

Main (argc, argv) int Argc; char ** argv; {printf ("Hello World! / N");

veteran

#include

Const int maxlen = 80;

Class outstring; class outstring {private: int size; char str [maxlen];

PUBLIC: OUTSTRING () {size = 0;} ~ outstring () {size = 0;} void print (); void propign (char * chrs);

Void outstring :: print () {int in; for (i = 0; i

Void outstring :: assign (char * chrs) {INT i; for (i = 0; chars [i]! = '/ 0'; i ) STR [i] = chrs [i]; size = i;} main INT Argc, Char ** Argv) {Outstring String; String.Assign ("Hello World!"); string.print ();}

boss

"George, I need a program that can print 'Hello World!'

Ok, change angle think about it, C may be your best friend, C father Stroustrup is designed C , in fact http://www.chunder.com/text/ididit.html is for our programmer Of course, if you really swear about C programmers, and you can't do the boss for a while, you can also consider making system administrators, sysadmin.

转载请注明原文地址:https://www.9cbs.com/read-99507.html

New Post(0)