分类: LINUX
2009-02-20 07:36:50
1、 进程
a) pid ——进程标识符
pid_t getpid()
pid_t getppid()
b)安全机制
int setgroups(size_t num, const gid_t *list)
int getgroups(size_t num,gid_t *list)
int setreuid(uid_t ruid, uid_t euid)
int setregid(gid_t rgid, gid_t egid)
int setuid(uid_t uid)
int setgid(gid_t gid)
int seteuid(uid_t uid)
int setegid(gid_t uid)
uid_t getuid()
uid_t geteuid()
gid_t getgid()
gid_t getegid()
c)程序参数
int main(int argc, char * argv[])
extern char *environ[]
const char *getenv(const char *name)
int putenv(const char *string)
int setenv(const char *name,const char *value,int overwrite)
d)资源使用
int getrusage(int who,struct rusage *usage) #include
e)建立使用限制
int getrlimit(int resources,struct rlimit *rlim)
int setrlimint(int resources,const struct rlimit *rlim)
f)创建子进程
#include
pid_t fork()
g)等待子进程结束
pid_t wait4(pid_t pid,int *status,int options,struct rusage *rusage)
pid_t wait(int *status)
pid_t waitpid(pid_t pid,int *status,int options)
pid_t wait3(int *status,int options,struct rusage *rusage)
h)运行新程序
int execl(const char *path,const char * arg0,…)
int execlp(const char *file,const char * arg0,…)
int execle(const char *path,const char * arg0,…)
int execv(const char *path,const char **arg)
int execvp(const char *file,const char **arg)
int execve(const char *file,const char **arg)
i) 终止
void exit(int exitcode)
void _exit(int exitcode)
int kill(pid_t pid,int signum)
j)简单子进程
int system(const char *cmd)
FIFE *popen(const char *cmd,const char *mode)
int pclose(FILE *stream)
2、 文件管理
a)文件描述符
stdin、stdout、stderr
b)文件操作
int close(int fd) #include
int open(char *pathname,int flags,mode_t mode)
int open(char *pathname,mode_t mode)
size_t read(int fd,void *buf,size_t length)
size_t write(int fd,const void *buf,size_t length)
int lseek(int fd,off_t offset,int whence)
SEEK_SET, SEEK_CUR, SEEK_END
int truncate(const char *pathname,size_tlength)
int ftruncate(int fd,size_t length)
int fsync(int fd)
int fdatasync(int fd)
c)查询和修改inode信息
#include
int stat(const char *pathname, struct stat * statbuf)
int lstat(const char *pathname, struct stat * statbuf)
int fstat(int fd, struct stat * statbuf)
d)测试访问权限
int access(const char *pathname,int mode)
F_OK、R_OK、W_OK、X_OK
#include
int chmod(const char *pathname,mode_t mode)
int fchmod(int fd,mode_t mode)
e)Ext3扩展属性
int ioctl(int fd, int request,void *arg)
EXT3_IOC_GETFLAGS, EXT3_IOC_SETFLAGS
f)操作目录项
int mknod(const char *pathname,mode_t mode,dev_t dev)
S_IFIFO、S_IFBLK,S_IFCHAR
Makedev(major,minor) major() minor()
int link(const char *origpath,const char *newpath) 硬链接
int symlink(const char *origpath,const char *newpath)符号链接
int readlink(const char *pathname,char *buf,size_t bufsize)
int unlink(char *pathname)
int rename(const char *oldpath,const char *newpath)
g)操作文件描述符
int fcntl(int fd,int command,long arg)
int pipe(int fds[2])
3、 信号处理
void *signal(int signum,void *handler)
SIG_IGN,SIG_DFL, SIGKILL,SIGSTOP
a)发送信号
int tkill(pid_t pid,int signum)
int raise(int signum)
#include
int sigemptyset(sigset_t *set)
int sigfillyset(sigset_t *set)
int sigaddyset(sigset_t *set,int signum)
int sigdelset(sigset_t *set,int signum)
int sigismember(const sigset_t *set,int signum)
int sigaction(int signum,struct sigaction *act,struct sigaction *oact)
int sigprocmask(int what,const sigset_t *set,sigset_t *oldset)
SIG_BLOCK,SIG_UNBLOCK,SIG_SETMASK
int sigpending(sigset_t *set)
int pause(void)
int sigsuspend(const sigset_t *mask)
获取信号信息
void handler(int signum,siginfo_t *siginfo,void *context)
struct sigaction{
union{
__sighandler_t sa_handler
__sigaction_t sa_sigaction
}
sigset_t sa_mask;
unsigned long sa_flags
}
si_signo
si_code:SI_USER,SI_QUEUE,SI_TKILL,SI_KERNEL
SIGSEGV SEGV_MAPERR
SEGV_ACCERR
SIGBUS BUS_ADRALN
BUS_ADDERR
BUS_OBJERR
SIGCHLD CLD_EXITED
CLD_KILLED
CLD_STOPPED
void *sigqueue(pid_t pid,int signum,const union sigval value)
union sigval{
int sival_int
void *sival_ptr
}
4、 高级文件操作
#include
int poll(struct pollfd *fds,int numfds,int timeout)
struct pollfd{
int fd
short events
short revents
}
POLLIN,POLLPRI,POLLOUT,POLLERR,POLLHUP,POLLNVAL
#include
int select(int numfds,fd_set *readfds,fd_set *writefds,fd_set *exceptfds,struct timeval *timeout)
FD_ZERO(fd_set *fds) FD_SET(int fd,fd_set *fds)
FD_CLR(int fd,fd_set *fds) FD_ISSET(int fd,fd_set *fds)
#include
int epoll_create(int numDescriptors)
int epoll_ctl(int epfd,int op,int fd,struct epoll_event *event)
int epoll_wait(int epfd,struct epoll_event *events,int maxevents,int timeout)
5、 目录操作
char *getcwd(char *buf,size_t size)
get_current_dir_name()
int chdir(const char *pathname)
int fchdir(int fd)
int chroot(const char *path) chdir(“/”)
int mkdir(const char *dirname,mod_t mode)
int rmdir(const char *pathname) ENOEMPTY
DIR *opendir(const char *pathname)
int closedir(DIR *dir)
struct dirent *readdir(DIR *dir) d_name d_ino
int rewinddir(DIR *dir)
文件名匹配
int glob(const char *pattern,int flags,int errfunc(const char *epath,int eerrno),glob_t *pglob)
typedef struct{
int gl_pathc
char **gl_pathv
int gl_offs
}glob_t
int globerr(const char *pathname,int globerror)
void globfree(glob_t *pglob)
GLOB_NOSPACE GLOB_ABEND GLOB_NOMATCH
6、 Socket网络
#include
struct sockaddr{
unsigned short sa_family
char sa_data[MAXSOCKADDRDATA]
}
基本套接字操作
int socket(int domain,int type,int protocol)
domain: PF_UNIX PF_INET PF_INET6
type: SOCK_STREAM SOCK_DGRAM SOCK_RAW
protocol: IPPROTO_ICMP、IPPROTO_ICMPV6、IPPROTO_IPIP
IPPROTO_IPV6、IPPROTO_RAW、IPPROTO_TCP、IPPROTO_UDP
int bind(int sock,struct sockaddr *my_addr,socklen_t addrlen)
int listen(int sock,int baklog)
int accept(int sock,struct sockaddr *my_addr,socklen_t *addrlen)
int connect(int sock,struct sockaddr *servaddr,socklen_t addrlen)
int getpeername(int s,struct sockaddr *addr,socklen_t *addrlen)
int getsockname(int s,struct sockaddr *addr,socklen_t *addrlen)
Unix域套接字
#include
struct sockaddr_un{
unsigned short sun_family
char sun_path[UNIX_PATH_MAX]
}
UNIX_PATH_MAX = 108