Linux系统调用详解之grn
NAMEgrn − groff preprocessor for gremlin filesSYNOPSISgrn[−Cv][−T dev][−M dir][−F dir][file...]It is possible to have whitespace between a command line option and its parameter.DESCRIPTIONgrn is a preprocessor for including gremlin pictures in groff input.grn writes to standard output, process-ing only input lines between two that start with.GS and.GE.Those lines must contain grn commands (see below). These commands request a gremlinfile, and the picture in that file is converted and placed in the troff input stream.The.GS request may be followed by a C, L, or R to center,left, or right justify the whole gremlin picture (default justification is center).If nofile is mentioned, the standard input is read.At the end of the picture, the position on the page is the bottom of the gremlin picture. If the grn entry is ended with.GF instead of.GE,the position is left at the top of the picture.Please note that currently only the −me macro package has support for.GS,.GE,and.GF.The following command-line options are understood:−T dev Prepare output for printer dev.The default device is ps.See groff(1) for acceptable devices.−M dir Prepend dir to the default search path for gremlinfiles. The default path is (in that order) the cur-rent directory,the home directory,/usr/share/groff/site-tmac,/usr/share/groff/site-tmac,and/usr/share/groff/1.18.1.4/tmac.−F dir Search dir for subdirectories dev name(name is the name of the device) for the DESCfile before the default font directories/usr/share/groff/site-font,/usr/share/groff/1.18.1.4/font,and/usr/lib/font.−C Recognize.GS and.GE(and.GF)even when followed by a character other than space or newline.−v Print the version number.GRN COMMANDSEach input line between.GS and.GE may have one grn command. Commands consist of one or two strings separated by white space, the first string being the command and the second its -mands may be upper or lower case and abbreviated down to one character.Commands that affect a picture’s environment (those listed before default,see below) are only in effect for the current picture: The environment is reinitialized to the defaults at the start of the next picture.The com-mands are as follows:1N2N3N4N Set gremlin’s text size number 1 (2, 3, or 4) to N points. The default is 12 (16, 24, and 36, respec-tively).roman fitalics fbold fspecial fSet the roman (italics, bold, or special) font to troff’s font f(either a name or number).Thedefault is R (I, B, and S, respectively).l fstipple fSet the stipple font to troff’s stipple font f(name or number).The command stipple may beabbreviated down as far as ‘st’ (to avoid confusion with special). There is no default for stipples(unless one is set by the default command), and it is invalid to include a gremlin picture with poly-gons without specifying a stipple font.x Nscale N Magnify the picture (in addition to any default magnification) by N,afloating point number larger than zero.The command scale may be abbreviated down to ‘sc’.narrow Nmedium Nthick NSet the thickness of gremlin’s narrow(medium and thick, respectively) lines to N times 0.15pt(this value can be changed at compile time).The default is 1.0 (3.0 and 5.0, respectively), whichcorresponds to 0.15pt (0.45pt and 0.75pt, respectively). A thickness value of zero selects thesmallest available line thickness.Negative values cause the line thickness to be proportional to thecurrent point size.pointscale<off/on>Scale text to match the picture.Gremlin text is usually printed in the point size specified with thecommands1,2,3,or4,reg a rdless of any scaling factors in the picture.Setting pointscale willcause the point sizes to scale with the picture (within troff’s limitations, of course).An operand ofanything but off will turn text scaling on.default Reset the picture environment defaults to the settings in the current picture.This is meant to be used as a global parameter setting mechanism at the beginning of the troff input file, but can beused at any time to reset the default settings.width NForces the picture to be N inches wide.This overrides any scaling factors present in the same pic-ture. ‘width0’is ignored.height NForces picture to be N inches high, overriding other scaling factors. If both ‘width’ and ‘height’are specified the tighter constraint will determine the scale of the picture.Height and width com-mands are not saved with a default command. They will, however, affect point size scaling if thatoption is set.file nameGet picture from gremlinfile name located the current directory (or in the library directory; see the−M option above). If twofile commands are given, the second one overrides the first.If namedoesn’t exist, an error message is reported and processing continues from the.GE line.NOTES ABOUT GROFFSince grn is a preprocessor,it doesn’t know about current indents, point sizes, margins, number registers, etc. Consequently,no troff input can be placed between the.GS and.GE requests. However,gremlin text is now processed by troff,so anything valid in a single line of troff input is valid in a line of gremlin text (barring ‘.’directives at the beginning of a line).Thus, it is possible to have equations within a gremlinfig-ure by including in the gremlinfile eqn expressions enclosed by previously defined delimiters (e.g.$$).When using grn along with other preprocessors, it is best to run tbl before grn,pic,and/or ideal to avoid overworking tbl.Eqn should always be run last.A picture is considered an entity,but that doesn’t stop troff from trying to break it up if it falls off the endof a page.Placing the picture between ‘keeps’ in −me macros will ensure proper placement.grn uses troff’s number registers g1through g9and sets registers g1and g2to the width and height of the gremlinfigure (in device units) before entering the.GS request (this is for those who want to rewrite these macros).GREMLIN FILE FORMATThere exist two distinct gremlinfile formats, the original format from the AED graphic terminal version, and the SUN or X11version. An extension to the SUN/X11version allowing reference points with neg-ative coordinates is not compatible with the AED version. As long as a gremlinfile does not contain neg-ative coordinates, either format will be read correctly by either version of gremlin or grn.The other differ-ence to the SUN/X11format is the use of names for picture objects (e.g., POLYGON, CURVE) instead ofnumbers. Files representing the same picture are shown in Table 1 in each format.sungremlinfile gremlinfile0240.00 128.000240.00 128.00CENTCENT 2240.00 128.00240.00 128.00185.00 120.00185.00 120.00240.00 120.00240.00 120.00296.00 120.00296.00 120.00*-1.00 -1.00232310 A Triangle 10A TrianglePOLYGON 6224.00 416.00224.00 416.0096.00 160.0096.00 160.00384.00 160.00384.00 160.00*-1.00 -1.00515100-1 -1Table 1. File examples•The first line of each gremlinfile contains either the string gremlinfile(AED version) or sun-gremlinfile(SUN/X11)•The second line of the file contains an orientation, and x and y values for a positioning point, sepa-rated by spaces.The orientation, either0or1,is ignored by the SUN/X11version.0means thatgremlin will display things in horizontal format (drawing area wider than it is tall, with menuacross top).1means that gremlin will display things in vertical format (drawing area taller than itis wide, with menu on left side).x and y are floating point values giving a positioning point to beused when this file is read into another file.The stuff on this line really isn’t all that important; avalue of ‘‘1 0.00 0.00’’is suggested.•The rest of the file consists of zero or more element specifications.After the last element specifi-cation is a line containing the string ‘‘-1’’.•Lines longer than 127 characters are chopped to this limit.ELEMENT SPECIFICATIONS•The first line of each element contains a single decimal number giving the type of the element (AED version) or its ASCII name (SUN/X11version). See Table 2.gremlin File Format−Object Type SpecificationAED Number SUN/X11Name Description0BOTLEFT bottom-left-justified text1BOTRIGHT bottom-right-justified text2CENTCENT center-justified text3VECTOR vector4ARC arc5CURVE curve6POLYGON polygon7BSPLINE b-spline8BEZIER Bézier10 TOPLEFT top-left-justified text11 TOPCENT top-center-justified text12 TOPRIGHT top-right-justified text13 CENTLEFT left-center-justified text14 CENTRIGHT right-center-justified text15 BOTCENT bottom-center-justified textTable 2.Type Specifications in gremlin Files•After the object type comes a variable number of lines, each specifying a point used to display the element. Each line contains an x-coordinate and a y-coordinate in floating point format, separatedby spaces.The list of points is terminated by a line containing the string ‘‘-1.0 -1.0’’(AED ver-sion) or a single asterisk, ‘‘*’’(SUN/X11version).•After the points comes a line containing two decimal values, giving the brush and size for the ele-ment. The brush determines the style in which things are drawn. For vectors, arcs, and curvesthere are six valid brush values:1−thin dotted lines2−thin dot-dashed lines3−thick solid lines4−thin dashed lines5−thin solid lines6−medium solid linesFor polygons, one more value, 0, is valid. It specifies a polygon with an invisible border.For text,the brush selects a font as follows:1−roman (R font in groff)2−italics (I font in groff)3−bold (B font in groff)4−special (S font in groff)If you’re using grn to run your pictures through groff,the font is really just a starting font: Thetext string can contain formatting sequences like‘‘\fI’’or‘‘\d’’which may change the font (as wellas do many other things).For text, the size field is a decimal value between 1 and 4.It selects thesize of the font in which the text will be drawn. For polygons, this size field is interpreted as astipple number to fill the polygon with.The number is used to index into a stipple font at printtime.•The last line of each element contains a decimal number and a string of characters, separated by a single space.The number is a count of the number of characters in the string.This information isonly used for text elements, and contains the text string.There can be spaces inside the text. Forarcs, curves, and vectors, this line of the element contains the string ‘‘0’’.NOTES ON COORDINATESgremlin was designed for AED s, and its coordinates reflect the AED coordinate space.For vertical pic-tures, x-values range 116 to 511, and y-values from 0 to 483.For horizontal pictures, x-values range from 0to511 and y-values range from 0 to 367.Although you needn’t absolutely stick to this range, you’ll get best results if you at least stay in this vicinity.Also, point lists are terminated by a point of (-1, -1), so you shouldn’t ever use negative coordinates.gremlin writes out coordinates using format ‘‘%f1.2’’; it’s proba-bly a good idea to use the same format if you want to modify the grn code.NOTES ON SUN/X11 COORDINATESThere is no longer a restriction on the range of coordinates used to create objects in the SUN/X11version of gremlin.Howev e r, files with negative coordinates will cause problems if displayed on the AED. FILES/usr/share/groff/1.18.1.4/font/dev name/DESC Device description file for device name.SEE ALSOgremlin(1),groff(1),pic(1),ideal(1)HISTORYDavid Slattengren and Barry Roitblat wrote the original Berkeley grn.Daniel Senderowicz and Werner Lemberg modified it for groff.。
Linux系统调用_详细全过程
优点
编程容易, 编程容易,从硬件设备的低级编程中解脱出来 提高了系统的安全性, 提高了系统的安全性,可以先检查请求的正确性
5.1 Linux系统调用-功能 系统调用系统调用
用户程序 . . . . 系统调用 . . . .
陷入处理机构 1)保护处理 机现场 2)取系统调 用功能号并 寻找子程序 入口 3)恢复处理 机现场并返 回 入口地址表 A0 A2 ... Ai ... An
• 将寄存器中的参数压入到 核心栈中( 核心栈中(这样内核才能使 用用户传入的参数。 用用户传入的参数。) • 因为在不同特权级之间控 制转换时,INT指令不同于 制转换时,INT指令不同于 CALL指令 指令, CALL指令,它不会将外层 堆栈的参数自动拷贝到内 层堆栈中。 层堆栈中。所以在调用系 统调用时, 统调用时,必须把参数指 定到各个寄存器中
系统子程序 A0 A1 sub 0 sub 1 ... Ai sub i ... An sub n
陷
入
指
令
0x80指令 5.2 Int 0x80指令
Linux中实现系统调用利用了i386体系结 Linux中实现系统调用利用了i386体系结 中实现系统调用利用了i386 构中的软件中断。即调用了int $0x80 构中的软件中断。即调用了 汇编指令。 汇编指令。 这条汇编指令将产生向量为128 128的编程异 这条汇编指令将产生向量为128的编程异 CPU便被切换到内核态执行内核函数 便被切换到内核态执行内核函数, 常,CPU便被切换到内核态执行内核函数, 转到了系统调用处理程序的入口: 转到了系统调用处理程序的入口: system_call()。 system_call()。
Linux系统调用_ Linux系统调用_详细全过程 系统调用
linux中对errno是EINTR的处理
linux中对errno是EINTR的处理慢系统调用(slow system call):此术语适用于那些可能永远阻塞的系统调用。
永远阻塞的系统调用是指调用有可能永远无法返回,多数网络支持函数都属于这一类。
如:若没有客户连接到服务器上,那么服务器的accept调用就没有返回的保证。
EINTR错误的产生:当阻塞于某个慢系统调用的一个进程捕获某个信号且相应信号处理函数返回时,该系统调用可能返回一个EINTR错误。
例如:在socket服务器端,设置了信号捕获机制,有子进程,当在父进程阻塞于慢系统调用时由父进程捕获到了一个有效信号时,内核会致使accept返回一个EINTR错误(被中断的系统调用)。
当碰到EINTR错误的时候,可以采取有一些可以重启的系统调用要进行重启,而对于有一些系统调用是不能够重启的。
例如:accept、read、write、select、和open之类的函数来说,是可以进行重启的。
不过对于套接字编程中的connect 函数我们是不能重启的,若connect函数返回一个EINTR错误的时候,我们不能再次调用它,否则将立即返回一个错误。
针对connect不能重启的处理方法是,必须调用select来等待连接完成。
在 linux 或者 unix 环境中, errno 是一个十分重要的部分。
在调用的函数出现问题的时候,我们可以通过 errno 的值来确定出错的原因,这就会涉及到一个问题,那就是如何保证 errno 在多线程或者进程中安全?我们希望在多线程或者进程中,每个线程或者进程都拥有自己独立和唯一的一个 errno ,这样就能够保证不会有竞争条件的出现。
一般而言,编译器会自动保证 errno 的安全性,但是为了妥善期间,我们希望在写 makefile 的时候把 _LIBC_REENTRANT 宏定义,比如我们在检查 <bits/errno.h> 文件中发现如下的定义:C代码# ifndef __ASSEMBLER__/* Function to get address of global `errno' variable. */extern int *__errno_location (void) __THROW __attribute__ ((__const__));# if !defined _LIBC || defined _LIBC_REENTRANT/* When using threads, errno is a per-thread value. */# define errno (*__errno_location ())# endif# endif /* !__ASSEMBLER__ */#endif /* _ERRNO_H */也就是说,在没有定义 __LIBC 或者定义 _LIBC_REENTRANT 的时候, errno 是多线程 / 进程安全的。
Linux系统调用分析报告
那么又是什么呢?
是对应的不同的系统调用的号码,权且叫它系统调用号吧.定义在中,如下:
* , *
....
将系统调用号放入中,留于在()之中用(上面提到过的).
要利用系统调用要把包含进去.
最后的收尾工作:
由来完成,如下.
:
$()
:()
()
$(), ()
():
$()
$()()?
:
$()
$'
()
$()
();
....
();
();
(<)
();
();
....
}
与都是宏.它们可以在之中找到如下.
() \
([])
() \
([])
() \
([])
() \
()
其中的也在同一文件中,如下.
() \
(" \\" \
" \\" \
" \\" \
" " \
:"" (*(( *) ())), \
"" (*(( *) ())) \
系统调用分析报告
计算机系沈华品
学号
摘要:
系统调用()简单的看作是操作系统提供的一种编程接口,它提供给编程人员
许多功能调用.(在高级语言如中,常以函数的形式出现).这些功能要自己实现起来是比较麻烦的.有了操作系统提供系统调用,使得编程人员不需要太多了解系统就能完成复杂的编程.例如,在程序中安排一条创建进程的系统调用,则便会为之创建一个新的进程.
Linux内核中系统调用详解
Linux内核中系统调用详解什么是系统调用?(Linux)内核中设置了一组用于实现各种系统功能的子程序,称为系统调用。
用户可以通过系统调用命令在自己的应用程序中调用它们。
从某种角度来看,系统调用和普通的函数调用非常相似。
区别仅仅在于,系统调用由(操作系统)核心提供,运行于核心态;而普通的函数调用由函数库或用户自己提供,运行于用户态。
随Linux核心还提供了一些(C语言)函数库,这些库对系统调用进行了一些包装和扩展,因为这些库函数与系统调用的关系非常紧密,所以习惯上把这些函数也称为系统调用。
为什么要用系统调用?实际上,很多已经被我们习以为常的C语言标准函数,在Linux 平台上的实现都是靠系统调用完成的,所以如果想对系统底层的原理作深入的了解,掌握各种系统调用是初步的要求。
进一步,若想成为一名Linux下(编程)高手,也就是我们常说的Hacker,其标志之一也是能对各种系统调用有透彻的了解。
即使除去上面的原因,在平常的编程中你也会发现,在很多情况下,系统调用是实现你的想法的简洁有效的途径,所以有可能的话应该尽量多掌握一些系统调用,这会对你的程序设计过程带来意想不到的帮助。
系统调用是怎么工作的?一般的,进程是不能访问内核的。
它不能访问内核所占内存空间也不能调用内核函数。
(CPU)(硬件)决定了这些(这就是为什么它被称作"保护模式")。
系统调用是这些规则的一个例外。
其原理是进程先用适当的值填充(寄存器),然后调用一个特殊的指令,这个指令会跳到一个事先定义的内核中的一个位置(当然,这个位置是用户进程可读但是不可写的)。
在(Intel)CPU中,这个由中断0x80实现。
硬件知道一旦你跳到这个位置,你就不是在限制模式下运行的用户,而是作为操作系统的内核--所以你就可以为所欲为。
进程可以跳转到的内核位置叫做sysem_call。
这个过程检查系统调用号,这个号码告诉内核进程请求哪种服务。
然后,它查看系统调用表(sys_call_table)找到所调用的内核函数入口地址。
操作系统--linux系统调用
实验报告一、理论分析(分值:20%)【从操作系统原理(理论)的角度阐述系统功能调用的过程】1、函数声明中都有asmlinkage限定词,用于通知编译器仅从栈中提取该函数的参数。
2、系统调用getXXX()在内核中被定义为sys_getXXX()。
系统调用号:在linux中,每个系统调用都赋予一个系统调用号,通过这个独一无二的号就可以关联系统调用。
当用户空间的进程执行一个系统调用的时候,这个系统调用号就被用来指明到底要执行哪个系统调用;进程不会提及系统调用的名称。
系统调用号一旦分配就不能再有任何变更(否则编译好的应用程序就会崩溃),如果一个系统调用被删除,它所占用的系统调用号也不允许被回收利用。
Linux 有一个"未使用"系统调用sys_ni_syscall(),它除了返回-ENOSYS外不做任何其他工作,这个错误号就是专门针对无效的系统调用而设的。
内核记录了系统调用表中所有已注册过的系统调用的列表,存储在sys_call_table中。
它与体系结构有关,一般在entry.s中定义。
这个表中为每一个有效的系统调用指定了唯一的系统调用号。
3、Makefile控制着整个内核的编译,在每个子目录下调用编译.c 文件,生成.o文件,生成新的内核。
会把新编译的sys_hello内核加入到系统调用中。
系统调用表geditsyscall_32.tbl中加入354 i386 hello sys_hello,当系统调用时可以在调用表中找到系统调用的号。
4、在syscalls.h中添加定义的内容的引用函数。
5、编译执行结果。
二、设计与实现(分值:30%)【阐述在Linux中添加系统功能调用的方法】1、在内核目录下创建hello文件夹 mkdir hello2、进入hello文件夹 cd hello3、创建hello.c的文件 vim hello.c4、加入代码#include <linux/kernel.h>asmlinkage long sys_hello(void){printk(“Hello world\n”);return 0;}5、在hello文件夹下添加Makefile文件 vim Makefile在文件里添加 obj-y := hello.o6、返回内核的根目录中,打开Makefile文件,在842行添加代码 vim Makefile 将core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/改为core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ hello/ 7、打开系统调用表 cd arch/x86/syscallsVim syscall_32.tbl在文件最后一行添加354 i386 hello sys_hello8、在调用函数名的文件中加入添加的函数cd include/linux/Vim syscalls.hasmlinkage long sys_hello(void);9、进行编译cd /usr/src/linux-3.16/sudo make menuconfigsudo make oldconfigmake -j410、安装编译好的内核sudo make modules_install installshutdown -r now重启后选择新的内核载入测试uname -r11、编写测试文件hello.c#include <stdio.h>#include <linux/kernel.h>#include <sys/syscall.h>#include <unistd.h>int main(){printf("%ld\n", syscall(354));return 0;}12、编译测试gcc -o hello.c hello./hello.outdmesg三、实验结果(分值:10%)【对实验结果进行简要分析和说明】测试文件调用系统调用号354,并且将返回结果0输出,dmesg可以将开机显示结果输出查看。
linux 系统调用流程
linux 系统调用流程Linux系统调用流程一、引言Linux是一种自由开源的操作系统,其核心部分是内核。
内核负责管理计算机的硬件资源,并提供各种系统调用供用户程序使用。
本文将介绍Linux系统调用的流程,包括用户程序如何通过系统调用接口向内核发起请求以及内核如何处理这些请求。
二、系统调用的定义系统调用是用户程序与内核之间的接口。
用户程序通过调用特定的系统调用函数来请求内核执行某些操作,例如读写文件、创建进程等。
内核接收到这些请求后,会进行相应的处理并返回结果给用户程序。
三、系统调用的流程1. 用户程序发起系统调用请求用户程序通过调用系统调用函数向内核发起请求。
这些系统调用函数通常由C库提供,并在用户程序中使用。
用户程序需要提供相应的参数,以告知内核所需的操作类型和操作对象。
2. 用户程序转入内核态用户程序发起系统调用请求后,会进入内核态。
在内核态下,用户程序的权限更高,可以执行一些普通用户无法执行的操作,例如访问硬件资源。
3. 内核处理系统调用请求内核接收到系统调用请求后,会根据请求的类型和参数进行相应的处理。
内核会首先检查请求的合法性,验证用户程序的权限和参数的有效性。
如果请求合法,内核会执行相应的操作;如果请求非法,内核会返回错误信息给用户程序。
4. 内核执行系统调用操作内核根据系统调用请求的类型和参数执行相应的操作。
例如,如果用户程序请求打开一个文件,内核会检查文件是否存在,并分配相应的文件描述符。
如果用户程序请求创建一个进程,内核会为进程分配资源并初始化进程上下文。
5. 内核返回结果给用户程序内核在执行完系统调用操作后,会将结果返回给用户程序。
如果操作成功,内核会返回相应的数据或完成状态;如果操作失败,内核会返回错误码,用户程序可以根据错误码进行相应的处理。
6. 用户程序继续执行用户程序在接收到内核返回的结果后,会根据结果进行相应的处理。
如果操作成功,用户程序可以继续执行后续的逻辑;如果操作失败,用户程序可以根据错误码采取相应的措施,例如重新尝试或向用户报告错误信息。
linux文件系统的系统调用命令
linux文件系统的系统调用命令Linux文件系统的系统调用命令Linux是一个开源的操作系统,提供了许多强大且灵活的系统调用命令来管理文件系统。
本文将深入探讨Linux文件系统的系统调用命令,包括创建、删除、重命名、复制和移动文件,以及设置文件权限和属性等功能。
一、文件系统简介在Linux系统中,文件系统是指对存储设备的管理和组织。
它使用层次结构来管理文件和目录,允许用户在存储设备上创建、访问和操作文件。
文件系统的目的是提供一种有效和可靠的方式来组织和存储数据。
二、系统调用命令Linux系统提供了一系列的系统调用命令,可以通过调用这些命令来操作文件系统。
1.创建文件创建文件是文件系统中的常见操作。
在Linux中,可以使用open系统调用命令来创建文件。
open命令的语法如下:int open(const char *pathname, int flags, mode_t mode);pathname:指定文件的路径和名称。
flags:指定文件的打开模式,如O_RDONLY(只读)、O_WRONLY (只写)、O_RDWR(读写)等。
mode:指定文件的权限模式。
open命令返回一个文件描述符,以便在后续的操作中引用该文件。
2.删除文件删除文件是通过unlink系统调用命令实现的。
unlink命令的语法如下:int unlink(const char *pathname);pathname:指定要删除的文件的路径和名称。
3.重命名文件重命名文件是通过rename系统调用命令实现的。
rename命令的语法如下:int rename(const char *oldpath, const char *newpath);oldpath:指定要重命名的文件的路径和名称。
newpath:指定重命名后的文件的路径和名称。
4.复制文件复制文件是通过使用read和write系统调用命令实现的。
read命令用于从源文件中读取数据,write命令用于将数据写入目标文件。
深入理解Linux系统调用
深入理解Linux系统调用大家好,我是小风哥。
在前两篇文章《为什么计算机需要操作系统》《系统调用与函数调用有什么区别》中我们了解了什么是系统调用、为什么需要系统调用、系统调用与函数调用有什么区别,那么在今天的文章中我们从理论来到现实,看看Linux中的系统调用是怎样实现的。
首先我们先来简单复习下之前讲解过的知识。
系统调用和普通的函数调用没有本质区别,普通的函数调用一般调用的是我们自己编写的函数或者其它库函数,而系统调用调用的则是内核中的函数,更学术一点的说法是这样的,所谓系统调用是指用户态程序请求操作系统提供的服务。
一提到服务,大家最先想到的一定是服务器,假设客户端是浏览器,浏览器发送http请求,服务器接收到请求后进行解析然后调用相应的hander,从本质上讲就是客户端触发了服务器端的某个函数的运行,这时我们说客户端请求了服务器端上的服务。
而系统调用与此类似,只不过用户态程序并不是通过http触发了操作系统中某个函数的运行,而是通过机器指令来触发的,因为用户态的App和操作系统运行在同一台计算机系统上,而客户端和服务器端运行在不同的计算机系统中(绝大部分情况下),因此客户端只能通过网络协议http来与服务器进行通信。
更通俗的说法就是所谓系统调用是指用户态的某个函数调用内核中的某个函数。
接下来我们用一段简单的hello world程序看下系统调用,这段程序需要运行在x86_64下:•.datamsg: .ascii 'Hello, world!\n' len = . - msg.text .global _start_start: movq $1, %rax movq $1, %rdi movq $msg, %rsi movq $len, %rdxsyscall movq $60, %rax xorq %rdi, %rdisyscall 使用以下命令编译:••$ gcc -c test.S$ ld -o test test.o然后执行:••./testHello, world!这段汇编代码成功的打印出了hello world,这段代码是什么意思呢?注意看.data这一段,这里说的是程序定义了哪些数据,.text段是说程序中包含了哪些执行,我们之前提到进程的内存布局时总是说数据段以及代码段,这里的数据段指的就是汇编中的.data段、代码段指的就是汇编中的.text段,现在你应该明白了吧。
Fedora Linux 系统调用或常用命令详细解析 rngd
NAMErngd − Check and feed random data from hardware device to kernel random deviceSYNOPSISrngd[−b,−−background][−f,−−foreground][−o,−−random-device=file][−r,−−rng-device=file][−s,−−random-step=nnn][−W,−−fill-watermark=nnn][−t,−−timeout=nnn][−?,−−help][−V,−−version] DESCRIPTIONThis daemon feeds data from a random number generator to the kernel’s random number entropy pool, after first checking the data to ensure that it is properly random.The−f or−−foreground options can be used to tell rngd to avoid forking on startup.This is typically used for debugging. The−f or−−foreground options, which fork and put rngd into the background automati-cally,are the default.The−r or−−rng-device options can be used to select an alternate source of input, besides the default /dev/hwrandom. The−o or−−random-device options can be used to select an alternate entropy output device, besides the default /dev/random. Note that this device must support the Linux kernel /dev/random ioctl API.FIXME: document random-step and timeoutOPTIONS−b,−−backgroundBecome a daemon (default)−f,−−foregroundDo not fork and become a daemon−ofile,−−random-device=fileKernel device used for random number output (default: /dev/random)−rfile,−−rng-device=fileKernel device used for random number input (default: /dev/hwrandom)−s nnn,−−random-step=nnnNumber of bytes written to random-device at a time (default: 64)−W n,−−fill−watermark=nnnOnce we start doing it, feed entropy to random-device until at leastfill-watermark bits of entropyare available in its entropy pool (default: 2048).Setting this too high will cause rngd to dominatethe contents of the entropy pool. Low values will hurt system performance during entropy starves.Do not setfill-watermark above the size of the entropy pool (usually 4096 bits).−t nnn,−−timeout=nnnInterval written to random-device when the entropy pool is full, in seconds, or 0 to disable(default: 60)−?,−−helpGive a short summary of all program options.−V,−−versionPrint program versionAUTHORSPhilipp RumpfJeff Garzik − jgarzik@Matt Sottek。
Linux Grub总结
Linux Grub总结GNU GRUB的前身为Grand Unified Bootloader。
目前GRUB分成GRUB legacy和GRUB2。
版本号是0.9x以及之前的版本都称为GRUB Legacy,从 1.x开始的就称为GRUB2。
grub2采用模块化的设计,主要配置文件是/boot/grub/grub.cfg,但是这个文件的权限是444,连root也不让修改,这是刻意为之的,不要修改文件权限,grub.cfg的内容更新由update-grub命令来更新,其实就是执行grub-mkconfig-o/boot/grub/grub.cfg来更新,此文件会在更新内核自动更新,在/boot/grub目录下有很多模块文件,以在按需时自动加载模块每段模块配置的加载以###BEGIN xxx###开始,以###END xxx###结尾。
一、grub2主要有三部分组成:update-grub和grub-mkconfig的作用都是一样的。
update-grub是Debian系Linux操作系统专用的,其它Linux操作系统不一定可以使用。
grub-mkconfig是Linux操作系统都通用的命令。
1.update-grubupdate-grub主要是在每次配置文件有更新后生成新的grub.cfg,其实update-grub是调用grub-mkconfig,在系统中还有一个update-grub2,发现他是调用update-grub2.grub-mkconfig调用grub-mkdevicemap和grub-probe生成grub.cfg3.grub-probe从给定的设备上探测设备信息二、/etc/default/grub/etc/default/grub控制grub-mkconfig的操作,grub里面是以键值对存在的选项,如果值有空格或者其他字符需要用引号引起来,参数如下#If you change this file,run'update-grub'afterwards to updateGRUB_DEFAULT=0#设置默认启动项,按menuentry顺序如果要默认从第四个菜单项启动,数字改为3,若改为saved,则默认为上次启动项GRUB_TIMEOUT="10"#设置进入默认启动项的等候时间,默认值10秒,按自己需要修改,单位为秒改改为零和负值为无限等待操作GRUB_DISTRIBUTOR=`lsb_release-i-s2>/dev/null||echo Debian`#获得发行版名称(比如Ubuntu, DebianGRUB_CMDLINE_LINUX_DEFAULT="quiet splash"#选择启动的环境,“quiet splash”为图像界面,“text”为文本界面#GRUB_CMDLINE_LINUX="noresume"#手动添加内核启动参数,比如acpi=off noapic等可在这里添加#Uncomment to disable graphical terminal(grub-pc only)#GRUB_TERMINAL=console#设置是否使用图形介面。
