注册 登录
编程论坛 Linux系统管理

计算机

madfrogme 发布于 2012-08-31 10:07, 9450 次点击
lstat() 与 stat() 类似, 但当文件是符号链接时,

lstat() 返回该符号链接的有关信息,

而不是由该符号链接引用文件的信息


[ 本帖最后由 madfrogme 于 2012-9-26 19:05 编辑 ]
71 回复
#52
madfrogme2012-10-02 01:55
Memory Operands.
In Intel syntax the base register is enclosed in ’[’ and ’]’ where as in AT&T they change to ’(’ and ’)’. Additionally, in Intel syntax an indirect memory reference is like

section:[base + index*scale + disp], which changes to

section:disp(base, index, scale) in AT&T.

One point to bear in mind is that, when a constant is used for disp/scale, ’$’ shouldn’t be prefixed.
#53
madfrogme2012-10-02 12:39
 Protected Mode and Real Mode each use a different format for the interrupt table — PM uses an 8-byte entry per interrupt and RM uses a 4-byte entry.
#54
madfrogme2012-10-02 15:24
sidt 语句
只有本站会员才能查看附件,请 登录
#55
madfrogme2012-10-02 16:26
In some cases, a single variable may serve as both the input and the output operand.

asm( "incl %0" : "=a"(var): "0"(var));

The register %eax is used as both the input and the output variable.

var input is read to %eax and updated %eax is stored in var again after increment.

"0" here specifies the same constraint as the 0th output variable
#56
madfrogme2012-10-02 16:35
out 语句
Usage: OUT port,accum

Modifies Flags: None

Transfers byte in AL,word in AX or dword in EAX to the specified hardware port address.

If the port number is in the range of 0-255 it can be specified as an immediate.

If greater than 255 then the port number must be specified in DX.

Since the PC only decodes 10 bits of the port address, values over 1023 can only be decoded by third party vendor equipment and also map to the port range 0-1023.


[ 本帖最后由 madfrogme 于 2012-10-2 17:36 编辑 ]
#57
madfrogme2012-10-02 21:04
If BIOS is to recognize a device as a bootable device,

then the device should have the values 0x55 and 0xaa at the 510th and 511th location.
#58
madfrogme2012-10-03 20:16
LODSB loads a byte from [DS:SI] or [DS:ESI] into AL. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) SI or ESI.
#59
madfrogme2012-10-03 23:23
pushl %ebx     # equivalent instructions
                                    subl $4,  %esp
                                    movl %ebx, (%esp)


popl %ebx             # equivalent instructions
                                movl (%esp), %ebx
                                addl   $4, %esp
#60
madfrogme2012-10-04 11:47
MOV [SI], AX.      

Will write the word contained in ax to the address DS:SI

MOV   ES:[DI],  AX.          

Will write the word contained in ax to the address es:di

COMSB  

will compare the byte at DS:SI to the byte at ES:DI,    set the zero flag if they are equal and decrement /increment SI and DI according to the state of the directing flag
#61
madfrogme2012-10-04 13:31
The interrupt gate is used to specify an interrupt service routine.  

 When you do INT 50 in assembly, running in protected mode,

the CPU looks up the 50th entry(located at 50*8) in the IDT.  

Then the interrupt gates selector and offset value is loaded.  

The selector and offset is used to call the interrupt service routine.  

When the IRET instruction is read , it returns.


[ 本帖最后由 madfrogme 于 2012-10-5 00:04 编辑 ]
#62
madfrogme2012-10-04 23:00
进程的重要性不仅由优先级指定的,而且还需要考虑保存在task_struct->se.load 的负荷权重

se(struct sched_entity)

set_load_weight 负责根据进程类型及静态优先级计算负荷权重

一般概念是这样, 进程每降低一个nice值, 则多获得10% 的CPU时间, 每升高一个nice 值,

则放弃10%的CPU时间。 为执行该策略, 内核将优先级转换为权重值

实时进程的权重是普通进程的两倍
.


[ 本帖最后由 madfrogme 于 2012-10-5 00:03 编辑 ]
#63
madfrogme2012-10-04 23:30
静态优先级(static_prio)是进程启动时分配的优先级

普通优先级(normal_priority) 表示基于进程的静态优先级和调度策略计算出的优先级

即使普通进程和实时进程具有相同的静态优先级, 其普通优先级也是不同的

进程分支时,子进程会继承普通优先级
#64
madfrogme2012-10-04 23:45
task_struct 中的 unsigned int policy 保存了对该进程应用的调度策略, Linux支持5个可能的值

SCHED_NORMAL 用于普通进程。它们通过完全公平调度器来处理

SCHED_BATCH 和 SCHED_IDLE 也通过完全公平调度器来处理,不过可用于次要的进程

SCHED_RR 和 SCHED_FIFO 用于实现软实时进程。由实时调度器类处理
#65
madfrogme2012-10-05 17:59
PID namespace は独立したマシンに見えるように PID の付け方を考慮したタスクセットを作成する機能です。

言い換えると、異なる namespace であれば同一の PID を持つことができるようになる機能です。

新たな namespace を作るには、CLONE_NEWPID フラグをセットした上で clone(2)システムコールを発行するだけでいいです。


[ 本帖最后由 madfrogme 于 2012-10-5 19:04 编辑 ]
#66
madfrogme2012-10-07 22:43
当进程调用abort() 函数时产生   SIGABRT 夭折信号

当由alarm() 函数设置的计时器超时后产生 SIGALRM 闹钟信号

linux 2.4.22支持31种不同信号

不存在编号为0 的信号, kill 函数对信号编号0 有特殊的应用

POSIX.1 将此种信号编号值称为空信号

对执行一个无效内存引用的进程产生的 SIGSEGV信号

进程调用kill()函数可将信号发送给另一个相同所有者的进程或进程组,或发送信号的是超级用户


[ 本帖最后由 madfrogme 于 2012-10-8 00:14 编辑 ]
#67
madfrogme2012-10-08 10:55
当后台执行一个进程时, 例如:

cc main.c &

shell 自动将后台进程对中断和退出信号的处理方式设置为忽略。

于是, 当按中断键时就不会影响后台进程。 如果没有执行这样的处理,

那么当按中断键时, 它不但会终止前台进程,还会终止所有后台进程。
#68
madfrogme2012-10-09 15:05
fd = open("./jim.mymemory", O_RDWR| O_CREAT, S_IRUSR| S_IWUSR );


S_IRUSR
  Permits the file's owner to read it.

S_IWUSR
  Permits the file's owner to write to it.

S_IRGRP
  Permits the file's group to read it.

S_IWGRP
  Permits the file's group to write to it.
#69
madfrogme2012-10-09 15:10
Upon successful completion, lseek() returns the resulting offset location as measured in bytes from the beginning of the file.

Otherwise, a value of -1 is returned and errno is set to indicate the error.
#70
madfrogme2012-10-09 15:23
msync -- synchronize a mmaped region

The msync() system call writes modified whole pages back to the filesystem and updates the file modification time.

Only those pages containing adds and len-1 succeeding locations will be examined.

int msync(void * addr, size_t len, int flags);

msync(addr,sizeof(int),MS_SYNC|MS_INVALIDATE);

MS_SYNC        Perform synchronous writes
MS_INVALIDATE        Invalidate all cached data
#71
madfrogme2012-10-09 15:28
The steps to create a piece of shared memory with mmap() are roughly:

Obtain a file descriptor to your target file (in my case a 1 MB file)
Call mmap() to map the file to your processes memory
Use the memory (NOTE: If you modify the memory call msync())
Call munmap() to disconnect the memory
Close the file.
Here is a very simple example of 2 process sharing memory via mmap().

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sys/stat.h>

int main(void) {
    size_t length = 1024 * 1024;
    off_t offset = 0;
    int prot = (PROT_READ| PROT_WRITE);
    int flags = MAP_SHARED;
    int fd = -1;
    pid_t pid;

    /*
     * Create file we are using for mmap. The file must be
     * size of memory we wish to map.
     */
    fd = open("./jim.mymemory", O_RDWR| O_CREAT, S_IRUSR| S_IWUSR );
    if (fd == 0) {
        int myerr = errno;
        printf("ERROR: open failed (errno %d %s)\n", myerr, strerror(myerr));
        return EXIT_FAILURE;
    }
    if (lseek(fd, length - 1, SEEK_SET) == -1) {
        int myerr = errno;
        printf("ERROR: lseek failed (errno %d %s)\n", myerr, strerror(myerr));
        return EXIT_FAILURE;
    }
    write(fd, "", 1);

    /*
     * Fork a child process to write to shared memory.
     * In the parent we simply wait for value to be written.
     */
    if ((pid = fork()) == 0) {
        /*Child process*/
        void * addr = 0;
       /*The offset in mmap() (the fifth argument) must be a PAGESIZE boundary (can be found out by getpagesize()).*/
        addr = mmap(NULL, length, prot, flags, fd, offset);
        if (addr == 0) {
            int myerr = errno;
            printf("ERROR (child): mmap failed (errno %d %s)\n", myerr,
                    strerror(myerr));
        }

        /*Write to memory*/
        printf("INFO (child): start write\n");
        *((int *) addr) = 0xcafebabe;
        printf("INFO (child): done write\n");

        /*
         * Call sync or parent will not see update until munmap is called.
         * Try commenting the below line out for fun.
         */
        msync(addr,sizeof(int),MS_SYNC|MS_INVALIDATE);

        /*Sleep to demonstrate msync*/
        printf("INFO (child): sleep start\n");
        sleep(5);/*Note: sleep seems to cause msync. Kinda interesting!*/
        printf("INFO (child): sleep done\n");

        if (munmap(addr, length) == -1) {
            int myerr = errno;
            printf("ERROR (child): munmap failed (errno %d %s)\n", myerr,
                    strerror(myerr));
        }
    } else {
        /*Parent process*/
        void * addr = 0;
        unsigned int readval = 0;
        addr = mmap(NULL, length, prot, flags, fd, offset);
        if (addr == 0) {
            int myerr = errno;
            printf("ERROR (parent): mmap failed (errno %d %s)\n", myerr,
                    strerror(myerr));
        }

        printf("INFO (parent): start read\n");
        while (readval != 0xcafebabe) {
            readval = *((int *) addr);
        }
        printf("INFO (parent): done read\n");

        if (munmap(addr, length) == -1) {
            int myerr = errno;
            printf("ERROR (parent): munmap failed (errno %d %s)\n", myerr,
                    strerror(myerr));
        }
    }

    if (close(fd) == -1) {
        int myerr = errno;
        printf("ERROR: close failed (errno %d %s)\n", myerr, strerror(myerr));
    }
    unlink ("./jim.mymemory");                /* remove directory entry*/
    return EXIT_SUCCESS;
}


[ 本帖最后由 madfrogme 于 2012-10-9 16:33 编辑 ]
#72
madfrogme2012-10-09 15:54
A reentrant function is one that can be used by more than one task concurrently without fear of data corruption.

A reentrant function can be interrupted at any time and resumed at a later time without loss of data.

A reentrant function:

Does not hold static data over successive calls

Does not return a pointer to static data; all data is provided by the caller of the function

Uses local data or ensures protection of global data by making a local copy of it

Must not call any non-reentrant functions
12