| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 9437 人关注过本帖
标题:计算机
取消只看楼主 加入收藏
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
进程的重要性不仅由优先级指定的,而且还需要考虑保存在task_struct->se.load 的负荷权重

se(struct sched_entity)

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

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

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

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


[ 本帖最后由 madfrogme 于 2012-10-5 00:03 编辑 ]

The quieter you become, the more you can hear
2012-10-04 23:00
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
静态优先级(static_prio)是进程启动时分配的优先级

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

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

进程分支时,子进程会继承普通优先级

The quieter you become, the more you can hear
2012-10-04 23:30
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
task_struct 中的 unsigned int policy 保存了对该进程应用的调度策略, Linux支持5个可能的值

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

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

SCHED_RR 和 SCHED_FIFO 用于实现软实时进程。由实时调度器类处理

The quieter you become, the more you can hear
2012-10-04 23:45
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
PID namespace は独立したマシンに見えるように PID の付け方を考慮したタスクセットを作成する機能です。

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

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


[ 本帖最后由 madfrogme 于 2012-10-5 19:04 编辑 ]

The quieter you become, the more you can hear
2012-10-05 17:59
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
当进程调用abort() 函数时产生   SIGABRT 夭折信号

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

linux 2.4.22支持31种不同信号

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

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

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

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


[ 本帖最后由 madfrogme 于 2012-10-8 00:14 编辑 ]

The quieter you become, the more you can hear
2012-10-07 22:43
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
当后台执行一个进程时, 例如:

cc main.c &

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

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

那么当按中断键时, 它不但会终止前台进程,还会终止所有后台进程。

The quieter you become, the more you can hear
2012-10-08 10:55
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
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.

The quieter you become, the more you can hear
2012-10-09 15:05
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
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.

The quieter you become, the more you can hear
2012-10-09 15:10
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
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

The quieter you become, the more you can hear
2012-10-09 15:23
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
收藏
得分:0 
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 编辑 ]

The quieter you become, the more you can hear
2012-10-09 15:28
快速回复:计算机
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018141 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved