PA0

世界诞生的前夜: 开发环境配置

Problems & Solutions

In the compling NEMU section I found some compile errors when running make menuconfig.

Here are some common sense about make errors:

  • Error messages are all either prefixed with the name of the program (usually make), or, if the error is found in a makefile, the name of the file and line number containing the problem.

  • make[<Integer>]: The <Integer> shows the deepth of recursion

  • Sometimes make errors are not fatal, especially in the presence of a - prefix on a recipe line, or the -k command line option. Errors that are fatal are prefixed with the string ***

You can found more detail in the Errors Generated by Make appendix.

Make always returns one of three error codes, as stated on gnu.org:

  • 0: Exit status is 'Successful'

  • 2: Make Encountered Errors

  • 1: Return response to -q (question) flag, indicating that targets require updating

It can be tested this by running make then running echo $? in the terminal to print the previous return code.

Make will print out other error codes it encounters (like the 127 in the problem below), but if it runs into an error it will always return an error code of 2.

[Extension] 💡 About Flex and Bison

Linux Flex/Bison evolves from Unix Lex/YACC, they are tools for building programs that handle structured input. They were originally tools for building compilers(From the user's point of view, Flex and Bison are tools for generating lexers and parsers respectively on Linux), but they have proven to be useful in many other areas.

Here are O'Reilly Flex & Bison book, GNU Flex and GNU Bison

[Review] 🔐 Where I was stuck

At first I was just focusing on the Warning from config.mk, ignored the following error info totally.

However this Warning info was not the reason why make stopped, it just print some hint, do not terminate the program.

To debug and solve problem, figure out what is error info from the output is of first importance.

必答题

  • su 认证失败是怎么回事? 出现 su: Authentication failure 可能的原因:

  • grep 提示 no such file or directory 是什么意思? 给出的文件路径不存在

  • 请问怎么卸载 Ubuntu? STFW. Uninstall Ubuntu safely from Windows dual boot mode basically follow these steps:

    • Change the boot order in UEFI settings and give priority to Windows Boot Manager. You may also delete Grub entry from UEFI setting, if your system gives you this option. If that doesn’t work then you’ll have to repair boot with a bootable Windows disk.

    • Deleting the Ubuntu partition from Windows.

  • C 语言的 xxx 语法是什么意思? STFW & RTFM. Please check C reference

  • ignoring return vaule of 'scanf' 是什么意思? On success, scanf returns the number of items successfully read. 代码中调用 scanf 的位置没有对返回值进行处理

  • 出现 curl: not found 该怎么办? 根据提示执行 sudo apt install curl

  • 为什么 strtok 返回 NULL? 根据 cppreference 的解释 strtok( char* str, const char* delim ) 函数在 str 指向的字符串中找到并返回指向下一个匹配 delimtoken 的指针,如果没有匹配的结果,返回 nullptr(在 C 语言中对应 NULL)

  • 为什么会有 Segmentation fault 这个错误? According to Wikipedia, A segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed (for example, attempting to write to a read-only location, or to overwrite part of the operating system).

  • 什么是 busybox? According to busybox.net and Wikipedia, BusyBox is a software suite that combines tiny versions of many common UNIX utilities into a single executable file,. It runs in a variety of POSIX environments such as Linux, Android, and FreeBSD, although many of the tools it provides are designed to work with interfaces provided by the Linux kernel. It was specifically created for embedded operating systems with very limited resources, provides a fairly complete environment for any small or embedded system. The utilities in BusyBox generally have fewer options than their full-featured GNU cousins; however, the options that are included provide the expected functionality and behave very much like their GNU counterparts.

读后感

谈谈你对"好的提问"以及"通过 STFW 和 RTFM 独立解决问题"的看法.

在遇到问题时,应该首先尝试自己独立解决:

  • 我遇到的问题是什么?

  • 遇到看不懂的信息,应该 STFW 和 RTFW

  • 问题的关键在哪里?可以忽略一些复杂但暂时不相关的信息

  • 我已经明白了我遇到的问题,如何解决?(STFW/RTFW/RTFSC)

Web 和 manual 中的信息对很多问题通常已经足够,STFW 和 RTFM 不仅能够解决问题,还可以让你学会独立解决问题的方式,提高下一次解决问题的效率。不做任何努力就询问他人可能花费很长的时间(别人很可能没有空、也没有义务回答你的问题!),但仍不能解决你的问题,或者解决了你的问题,但你没有从中学到任何有用的东西,下一次遇到问题时你还要求助他人。

正确的 STFW 方式同样重要,比如使用 Google 与 Wikipedia 搜索一般性问题,在 Stackoverflow 论坛上搜索技术问题等。好的 STFW 能让你快速找到解决问题的方法,并能够从中学到有用的知识。

当你做了大量努力并且认真思考过仍然不能解决问题,再向别人提问。

“好的提问” 应该是:

  • 简洁、清晰地描述自己的根本问题是什么

  • 自己做了哪些努力,但仍得到什么结果

  • 列出问题产生的环境

  • 标出重点

  • 在正确的地方、向正确的人提问

  • 正确的提问方式使你的问题容易回复

  • 不要添加多余的内容

  • 有礼貌

蓝框思考题

Where is GUI?

Have you wondered if there is something that you can do it in CLI, but can not in GUI? Have no idea? If you are asked to count how many lines of code you have coded during the 程序设计基础 course, what will you do?

Assume all my code during the 程序设计基础 course are stored in the ~/Labs/pb directory and all my source code files end with .h or .c. I can use the following command:

find ~/Labs/pb -name '*.[ch]' | xargs wc --lines

to count how many lines of code I have coded.

That's just what CLI can do while GUI cannot, deal with huge workload using just one line of command. CLI makes work faster and easier.

Why executing the "poweroff" command requires superuser privilege?

Can you provide a scene where bad thing will happen if the poweroff command does not require superuser privilege?

GNU/Linux operating systems are multi-user. When there are some other users are logged into the system, if poweroff command works without superuser privilege, one user can easily terminate and damage other users' work, they may still running their programs when you execute poweroff.

[More] 🔎 However, I found that I can execute the poweroff command without superuser privilege in Ubuntu22.04 LTS. Here is Why does `reboot` and `poweroff` work without super user privileges in Ubuntu 16.04?, it says that Ubuntu 16.04 (so I think it should also works fo 22.04) is "smart" enough to realize when there is in fact another user logged in. If the number of users logged in is more then 1, executing the poweroff command still require superuser privilege.

Things behind scrolling

You should have used scroll bars in GUI. You may take this for granted. So you may consider the original un-scrollable terminal (the one you use when you just log in) the hell. But think of these: why the original terminal can not be scrolled? How does tmux make the terminals scrollable? And last, do you know how to implement a scroll bar?

GUI is not something mysterious. Remember, behind every elements in GUI, there is a story about it. Learn the story, and you will learn a lot. You may say "I just use GUI, and it is unnecessary to learn the story." Yes, you are right. The appearance of GUI is to hide the story for users. But almost everyone uses GUI in the world, and that is why you can not tell the difference between you and them.

From Wikipedia, scrolling does not change the layout of the text or pictures but moves the user's view across what is apparently a larger image that is not wholly seen. Scrolling may take place in discrete increments (perhaps one or a few lines of text at a time), or continuously (smooth scrolling).

Based my observation I think scrolling using keys is take place in discrete increments and using mouse is smooth scrolling.

I guess to implement a scroll bar (or scrolling with keys) needs firstly capture the position of mouse when cliking and the moment it releases, then the vertical movement distance of the cursor (or the key-bind that triggers the scroll). To display the scrolling effect, we also need to store the command executed before in this shell and their output. When scrolling are triggered, compute showing what commands and their output based on the size of this shell, scrolling distance, font size and so on, then display them.

What happened?

You should know how a program is generated in the 程序设计基础 course. But do you have any idea about what happened when a bunch of information is output to the screen during make is executed?

From how make works, make reads the makefile in the current directory and begins by processing the first rule. By default, executing make without parameter (you can use it to specify the target) starts with the first target, which is make strives ultimately to update.

But before make can fully process this rule, it must process the rules for the files that target depends on. Each of these files is processed according to its own rule. These rules say to update each ‘.o’ file by compiling its source file. The recompilation must be done if the source file, or any of the header files named as prerequisites, is more recent than the object file, or if the object file does not exist.

The other rules are processed because their targets appear as prerequisites of the goal. If some other rule is not depended on by the goal (or anything it depends on, etc.), that rule is not processed, unless you tell make to do so (with a command such as make clean).

What make do is just execute a seqence of commands in shell from the rules described by the makefile, usually the goal is to compile source files, link object files, and finally get an executable.

Last updated