APUE学习之旅-第一章:UNIX System Over view

       看了一个多星期,才把第一章UNIX System Over view看完,可见我的英文水平有多差,而且看完以后脑袋里没有一点印象,来写这篇文章也是重头浏览了一遍的,也是给自己一个学习总结吧。

     这一章主要讲的是UNIX系统的概述吧,第1小节讲的是介绍UNIX,我觉得这句话有代表性:Describing the UNIX System in a strictly linear fashion, without any forward references to terms that haven’t been described yet, is nearly impossible (and would probably be boring).大体知道是什么意思,英文水平有限就不做翻译了!

     第2小节讲的是UNIX Architecture,下面有个图描述的很直观,

In a strict sense, an operating system can be defined as the software that controls the hardware resources of the computer and provides an environment under which programs can run. Generally, we call this software the kernel, since it is relatively small and resides at the core of the environment.

     第3小节Logging In,当我们输入用户名密码登录的时候,系统会把我们输入的用户名密码与/etc/passwd里的password file做检查的,这是里面的组成sar:x:205:105:Stephen Rago:/home/sar:/bin/ksh,这里面经过加密了的,但是这句话All contemporary systems have moved the encrypted password to a different file.In Chapter 6, we’ll look at these files and some functions to access them.令我很感兴趣,所以我很期待第六章哦。至于还有其他的都是讲的一些shell script与UNIX版本的事了,在这里不多做介绍哈。

     第4小节,Files and Directories,文件系统:The UNIX file system is a hierarchical arrangement of directories and files.文件名:The names in a directory are called filenames.不过要注意的是,仅有两个字符不能出现在文件名中slash character (/) and the null character(空字符)。这节同样还提到了.和..的,Two filenames are automatically created whenever a new directory is created: .(called dot) and .. (called dot-dot).这两字符的区别:Dot refers to the current directory, and dot-dot refers to the parent directory. In the root directory, dot-dot is the same as dot。还有文件路径两种介绍:A pathname that begins with a slash is called an absolute pathname(绝对路径)、it’s called a relative pathname(相对路径).这节还告知了我们一个强大的功能man ,不会用的都找它,以后记住不懂的就找男人,比如我要知道ls的用法,详细情况,就输入 man ls。man找不到就找man 1,man 1 找不到 就找 man 2 ....,至于目录,就是Working Directory and Home Directory

     第5小节Input and Output,File Descriptors:File descriptors are normally small non-negative integers that the kernel uses to identify the files accessed by a process. Whenever it opens an existing file or creates a new file, the kernel returns a file descriptor that we use when we want to read or write the file。觉得还是英文表达的好一点By convention, all shells open three descriptors whenever a new program is run: standard input, standard output, and standard error。无缓冲I/O:By convention, all shells open three descriptors whenever a new program is run: standard input, standard output, and standard error。for example:

#include "apue.h"
#define BUFFSIZE 4096
int
main(void)
{
int n;
char buf[BUFFSIZE];
while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0)
if (write(STDOUT_FILENO, buf, n) != n)
err_sys("write error");
if (n < 0)
err_sys("read error");
exit(0);

}

     第6小节,Programs and Processes,程序是一个驻扎在硬盘上的目录上的一个可执行文件,Processes and Process ID,一个程序的执行被称为进程,UNIX系统保证每一个进程都有唯一的一个数字标识符成为进程ID,打印进程ID:

#include "apue.h"
int
main(void)
{
  printf("hello world from process ID %ld\n", (long)getpid());
  exit(0);

}

Process Control,进程控制的三个主要函数:fork, exec, and waitpid

Threads and Thread IDs,All threads within a process share the same address space, file descriptors, stacks,and process-related attributes.第12章会详细讲解线程。。。

     第7小节,Error Handling:When an error occurs in one of the UNIX System functions, a negative value is often
returned, and the integer errno is usually set to a value that tells why.Two functions are defined by the C standard to help with printing error message

Example:

#include <errno.h>
int
main(int argc, char *argv[])
{
fprintf(stderr, "EACCES: %s\n", strerror(EACCES));
errno = ENOENT;
perror(argv[0]);
exit(0);

}

     第8小节,User Identification,用户标识,包括user ID和group ID,证明你所属的组和名。The user ID from our entry in the password file is a numeric value that identifies us to the system.Group ID:Our entry in the password file also specifies our numeric group ID。打印user ID和group ID:

#include "apue.h"
int
main(void)
{
printf("uid = %d, gid = %d\n", getuid(), getgid());
exit(0);

}

Supplementary Group IDs:In addition to the group ID specified in the password file for a login name, most versions of the UNIX System allow a user to belong to other groups.

     第9小节,Signals:Signals are a technique used to notify a process that some condition has occurred.The process has three choices for dealing with the signal.1. Ignore the signal.2. Let the default action occur.3. Provide a function that is called when the signal occurs

     第10小节,Time Values,UNIX有两种时间值:Calendar time and Process time.Calendar time:This value counts the number of seconds since the Epoch: 00:00:00 January 1, 1970, Coordinated Universal Time (UTC).(Older manuals refer to UTC as Greenwich Mean Time.)从公园1970年1月1日00:00:00开始计数,以秒为单位。

查看时间:

$ cd /usr/include
$ time -p grep _POSIX_SOURCE */*.h > /dev/null
real 0m0.81s
user 0m0.11s
sys 0m0.07s

     第11小节,System Calls and Library Functions,这节主要讲的是系统调用和库函数的区别,不过最核心的区别有一张图可以很清楚的阐述:


从各个角度说两者的区别:From an implementor’s point of view, the distinction between a system call and a library function is fundamental. From a user’s perspective, however, the difference is not as critical. From our perspective in this text, both system calls and library functions appear as normal C functions. Both exist to provide services for application programs.We should realize, however, that we can replace the library functions, if desired,whereas the system calls usually cannot be replaced.书中举的事内存分配的例子,库函数malloc 和 系统调用sbrk,上面的图就是这两个例子的区别。

      最后一节总结我就讲了,最主要是后面的几个习题除了第一题我知道怎么做后面的貌似没理解,求大牛顺便指点一下;

Exercises
1.1 Verify on your system that the directories dot and dot-dot are not the same, except in the
root directory.(这题答案我上面讲了的)
1.2 In the output from the program in Figure 1.6, what happened to the processes with process
IDs 852 and 853?
1.3 In Section 1.7, the argument to perror is defined with the ISO C attribute const, whereas
the integer argument to strerror isn’t defined with this attribute. Why?
1.4 If the calendar time is stored as a signed 32-bit integer, in which year will it overflow? How
can we extend the overflow point? Are these strategies compatible with existing
applications?
1.5 If the process time is stored as a signed 32-bit integer, and if the system counts 100 ticks per
second, after how many days will the value overflow?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
东南亚位于我国倡导推进的“一带一路”海陆交汇地带,作为当今全球发展最为迅速的地区之一,近年来区域内生产总值实现了显著且稳定的增长。根据东盟主要经济体公布的最新数据,印度尼西亚2023年国内生产总值(GDP)增长5.05%;越南2023年经济增长5.05%;马来西亚2023年经济增速为3.7%;泰国2023年经济增长1.9%;新加坡2023年经济增长1.1%;柬埔寨2023年经济增速预计为5.6%。 东盟国家在“一带一路”沿线国家中的总体GDP经济规模、贸易总额与国外直接投资均为最大,因此有着举足轻重的地位和作用。当前,东盟与中国已互相成为双方最大的交易伙伴。中国-东盟贸易总额已从2013年的443亿元增长至 2023年合计超逾6.4万亿元,占中国外贸总值的15.4%。在过去20余年中,东盟国家不断在全球多变的格局里面临挑战并寻求机遇。2023东盟国家主要经济体受到国内消费、国外投资、货币政策、旅游业复苏、和大宗商品出口价企稳等方面的提振,经济显现出稳步增长态势和强韧性的潜能。 本调研报告旨在深度挖掘东南亚市场的增长潜力与发展机会,分析东南亚市场竞争态势、销售模式、客户偏好、整体市场营商环境,为国内企业出海开展业务提供客观参考意见。 本文核心内容: 市场空间:全球行业市场空间、东南亚市场发展空间。 竞争态势:全球份额,东南亚市场企业份额。 销售模式:东南亚市场销售模式、本地代理商 客户情况:东南亚本地客户及偏好分析 营商环境:东南亚营商环境分析 本文纳入的企业包括国外及印尼本土企业,以及相关上下游企业等,部分名单 QYResearch是全球知名的大型咨询公司,行业涵盖各高科技行业产业链细分市场,横跨如半导体产业链(半导体设备及零部件、半导体材料、集成电路、制造、封测、分立器件、传感器、光电器件)、光伏产业链(设备、硅料/硅片、电池片、组件、辅料支架、逆变器、电站终端)、新能源汽车产业链(动力电池及材料、电驱电控、汽车半导体/电子、整车、充电桩)、通信产业链(通信系统设备、终端设备、电子元器件、射频前端、光模块、4G/5G/6G、宽带、IoT、数字经济、AI)、先进材料产业链(金属材料、高分子材料、陶瓷材料、纳米材料等)、机械制造产业链(数控机床、工程机械、电气机械、3C自动化、工业机器人、激光、工控、无人机)、食品药品、医疗器械、农业等。邮箱:market@qyresearch.com

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值