解释器文件
所有现今的UNIX系统都支持解释器文件(interpreter file)。这种文件是文本文件, 其起始行的形式是:
#! pathname[optional-argument]
在感叹号和pathname之间的空格是可选的,最常见的解释器文件以下列行开始。
#! /bin/bash
内核执行的是解释器文件第一行的pathname所指定的文件,并不是解释器文件。
函数system
#include <stdlib.h> int system(const char *cmdstring); |
---|
如果cmdstring是一个空指针,则仅当命令处理程序可用时,system返回非0值,这一特征可以确定在一个给定的操作系统上是否支持system函数。
用户标识
可用getlogin函数获得此登录名。
#include <unistd.h> char *getlogin(void); 返回值:若成功,返回指向登陆名字符串的指针;若出错,返回NULL |
---|
进程调度
UNIX系统历史上对进程提供的只是基于调度优先级的粗粒度的控制。调度策略和调度优先级是由内核确定的。进程可以通过调整nice值选择以更低优先级运行。
进程可以通过nice函数获取或更改它的nice值。使用这个函数,进程只能影响自己的nice值,不能影响其它任何进程的nice值。
#include<unistd.h> int nice(int incr); 返回值:若成功,返回新的nice值NZERO;若出错,返回-1 |
---|
getpriority函数可以像nice函数那样用于获取进程的nice值,但getprioprity函数还可以获取一组相关进程的nice值。
#include <sys/resource.h> int getpriority(int which, id_t who); 返回值:若成功,返回-NZERO~NZERO之间的nice值;若出错,返回-1 |
---|
setprioprity函数可用于为进程、进程组和属于特定用户ID的所有进程设置优先级。
#include <sys/resource.h> int setpriority(int which, id_t who, int value); 返回值:若成功,返回0;若出错,,返回-1 |
---|
进程时间
任一进程都可以调用函数times函数获得它自己以及终止子进程的墙上时钟时间、用户CPU时间和系统CPU时间。
#include <sys/times.h> closk_t times(struct tms *buf); 返回值:若成功,返回流逝的墙上时钟时间(以时钟滴答数为单位);若出错,返回-1 |
---|
此函数填写由buf指向的tms结构,该结构定义如下:
struct tms {
clock_t tms_utime; /* user CPU time /
clock_t tms_stime; / system CPU time /
clock_t tms_cutime; / user CPU time, terminated children /
clock_t tms_cstime; / system CPU time, terminated children */
};
注意:此结构没有包含墙上时钟时间。times函数返回墙上时钟时间作为其函数值。