免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: zhlyp
打印 上一主题 下一主题

弱弱的问一些面试的问题 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2008-09-25 13:22 |只看该作者
谁见过gnu.h?

论坛徽章:
0
12 [报告]
发表于 2008-09-25 23:43 |只看该作者
原帖由 zhlyp 于 2008-9-22 23:07 发表
一直从事嵌入式方面的工作
忽然接到一个linux软件编程的面试通知
结果被问傻了

这里有两个问题,希望帮我解答解答

1,编程时不加“gnu.h”会产生什么影响?
2,为什么网络不像其他设备一样在dev下产生 ...


1. 我想这个gnu.h只是一个泛指,就和foo一样,这里,我觉得应该是和函数的声明相关,因为在gnu.h中可能有一些函数的声明,虽然在C语言中在调用函数之前可以不进行声明。但是这样会隐藏一些错误,即是说调用函数时的参数与实际的实现有不同。比如实际的定义是foo(),但是你调用的时候可以直接foo(10),这样会引起一些潜在的错误。所以说如果事先进行了声明,则不会出现这种情况。在C++中要求函数使用之前必须声明。就是为了避免这个问题。

2. Linux Device Driver3上面是这样说的:

  1. Not being a stream-oriented device, a network interface isn't easily mapped to a node in the filesystem, as /dev/tty1 is. The Unix way to provide access to interfaces is still by assigning a unique name to them (such as eth0), but that name doesn't have a corresponding entry in the filesystem. Communication between the kernel and a network device driver is completely different from that used with char and block drivers. Instead of read and write, the kernel calls functions related to packet transmission.
复制代码

也就是说,对于网络设备来说,因为它会与很多设备进行交互,所以不能够使用简单的read、write的系统调用来对它进行操作。而应该使用一些其它的方式。
好像在《Linux网络体系架构》一书上也有对于这个的讲解,不过一时没有找到。以后找到了再贴出来。

论坛徽章:
95
程序设计版块每日发帖之星
日期:2015-09-05 06:20:00程序设计版块每日发帖之星
日期:2015-09-17 06:20:00程序设计版块每日发帖之星
日期:2015-09-18 06:20:002015亚冠之阿尔艾因
日期:2015-09-18 10:35:08月度论坛发贴之星
日期:2015-09-30 22:25:002015亚冠之阿尔沙巴布
日期:2015-10-03 08:57:39程序设计版块每日发帖之星
日期:2015-10-05 06:20:00每日论坛发贴之星
日期:2015-10-05 06:20:002015年亚冠纪念徽章
日期:2015-10-06 10:06:482015亚冠之塔什干棉农
日期:2015-10-19 19:43:35程序设计版块每日发帖之星
日期:2015-10-21 06:20:00每日论坛发贴之星
日期:2015-09-14 06:20:00
13 [报告]
发表于 2008-09-26 09:20 |只看该作者
原帖由 scutan 于 2008-9-25 23:43 发表

Not being a stream-oriented device

是 Note being a stream-oriented ... 吧?

另外,你后面的“也就是说”也和前面的英文对不上嘛

论坛徽章:
0
14 [报告]
发表于 2008-09-26 09:25 |只看该作者
原帖由 tentacle 于 2008-9-24 10:41 发表
1、我从没听说过,孤陋寡闻了
2、我觉的是网络为字符设备,dev下为块设备

网络设备不是字符设备也不是块设备,就是网络设备。/dev下字符设备和块设备都有

论坛徽章:
0
15 [报告]
发表于 2008-09-26 09:29 |只看该作者
原帖由 scutan 于 2008-9-25 23:43 发表


1. 我想这个gnu.h只是一个泛指,就和foo一样,这里,我觉得应该是和函数的声明相关,因为在gnu.h中可能有一些函数的声明,虽然在C语言中在调用函数之前可以不进行声明。但是这样会隐藏一些错误,即是说调用 ...

看看这个说法:
Linux驱动分为字符设备、块设备和网络设备驱动。字符设备是能够像字节流一样被访问的设备,大多数字符设备只能被顺序访问。块设备驱动程序提供面向块的设备的访问,这种设备以随机访问的方式传输数据,并且数据总是具有固定大小的块,这些块中包含了2的几次幂字节的数据,硬盘就是典型的块设备。

      在Linux中,字符设备和块设备都是通过文件系统节点被访问,块驱动程序除了向内核提供与字符驱动程序相同的接口外,还提供了专门面向块驱动设备的接口。

      网络接口在系统中的角色与一个已挂装的块设备非常相似。块设备将自己注册到blk_dev数组以及其他内核结构中,然后通过自己的request函数在发生请求时“发送”和“接收”数据块。同样,网络接口也必须在特定的数据结构中注册自己,以便在与外界交换数据包时被调用。但是,块设备接口与网络数据包发送接口之间存在不同。普通的文件操作对网络接口来说没有任何意义,因此,Unix的“所有东西都是文件”这一思想无法应用于网络接口。这样,网络接口存在于它们自己的名字空间中,同时导出一组不同的操作。同一网络接口可以由几百个套接字同时复用。块没备驱动只对来自内核的请求做出响应,而网络驱动程序却异步地接收来自外界的数据包。


关于网络设备<<understanding linux network internals>>说明更详细,偶目前只看了一点,还没啥心得:wink:

[ 本帖最后由 duanjigang 于 2008-9-26 09:31 编辑 ]

论坛徽章:
0
16 [报告]
发表于 2008-09-26 09:38 |只看该作者
原帖由 MMMIX 于 2008-9-26 09:20 发表

是 Note being a stream-oriented ... 吧?

另外,你后面的“也就是说”也和前面的英文对不上嘛


噢,书中确实是Not being,即是说网络设备不是一个面向流的设备。

我后面说的是我自己的理解。不是照着书翻译的。因为我记得我在另外的一个地方看到了为什么在/dev目录下没有节点的原因。但我忘了是在哪儿看到的了。

论坛徽章:
95
程序设计版块每日发帖之星
日期:2015-09-05 06:20:00程序设计版块每日发帖之星
日期:2015-09-17 06:20:00程序设计版块每日发帖之星
日期:2015-09-18 06:20:002015亚冠之阿尔艾因
日期:2015-09-18 10:35:08月度论坛发贴之星
日期:2015-09-30 22:25:002015亚冠之阿尔沙巴布
日期:2015-10-03 08:57:39程序设计版块每日发帖之星
日期:2015-10-05 06:20:00每日论坛发贴之星
日期:2015-10-05 06:20:002015年亚冠纪念徽章
日期:2015-10-06 10:06:482015亚冠之塔什干棉农
日期:2015-10-19 19:43:35程序设计版块每日发帖之星
日期:2015-10-21 06:20:00每日论坛发贴之星
日期:2015-09-14 06:20:00
17 [报告]
发表于 2008-09-26 09:52 |只看该作者
原帖由 scutan 于 2008-9-26 09:38 发表


噢,书中确实是Not being,即是说网络设备不是一个面向流的设备。

嗯,找到了,在 chap 1。说是 TCP 之类的连接是面向流的,可网络驱动只处理 packet。因此网络设备也就不是流设备了。
我后面说的是我自己的理解。不是照着书翻译的。因为我记得我在另外的一个地方看到了为什么在/dev目录下没有节点的原因。

哦,这样啊。

论坛徽章:
3
戌狗
日期:2014-09-10 17:07:162015年辞旧岁徽章
日期:2015-03-03 16:54:15wusuopu
日期:2016-06-17 17:43:45
18 [报告]
发表于 2008-09-26 16:14 |只看该作者
In addition to character and block devices, network devices represent the third category of adapters in the Linux kernel [RuCo01]. This section describes the concept of network devices from the perspective of higher-layer protocols and their data structures and management.

Network adapters differ significantly from the character and block devices introduced in Section 2.5. One of their main characteristics is that they have no representation in the device file system /dev/, which means that they cannot be addressed by simple read-write operations. In addition, this is not possible because network devices work on a packet basis; a behavior comparable to character-oriented devices can be achieved only by use of complex protocols (e.g., TCP). For example, there are no such network devices as /dev/eth0 or /dev/atm1. Network devices are configured separately by the ifconfig tool on the application level. More recently, another tool available is ip, which can be used for extensive configuration of most network functions.

One of the reasons why network devices are so special is that the actions of a network adapter cannot be bound to a unique process; instead, they run in the kernel and independently of user processes [RuCo01]. For example, a hard disk is requested to pass a block to the kernel: The action is triggered by the adapter (in the case of network adapters), and the adapter has to explicitly request the kernel to pass the packet.

论坛徽章:
0
19 [报告]
发表于 2008-09-30 20:31 |只看该作者
学习  linux不是叫gunlinux吗

论坛徽章:
95
程序设计版块每日发帖之星
日期:2015-09-05 06:20:00程序设计版块每日发帖之星
日期:2015-09-17 06:20:00程序设计版块每日发帖之星
日期:2015-09-18 06:20:002015亚冠之阿尔艾因
日期:2015-09-18 10:35:08月度论坛发贴之星
日期:2015-09-30 22:25:002015亚冠之阿尔沙巴布
日期:2015-10-03 08:57:39程序设计版块每日发帖之星
日期:2015-10-05 06:20:00每日论坛发贴之星
日期:2015-10-05 06:20:002015年亚冠纪念徽章
日期:2015-10-06 10:06:482015亚冠之塔什干棉农
日期:2015-10-19 19:43:35程序设计版块每日发帖之星
日期:2015-10-21 06:20:00每日论坛发贴之星
日期:2015-09-14 06:20:00
20 [报告]
发表于 2008-09-30 20:38 |只看该作者
原帖由 虑而后能得 于 2008-9-30 20:31 发表
学习  linux不是叫gunlinux吗

是 GNU/Linux
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP