Chinaunix首页 | 论坛 | 博客
  • 博客访问: 591187
  • 博文数量: 126
  • 博客积分: 4379
  • 博客等级: 上校
  • 技术积分: 2110
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-06 22:35
文章分类

全部博文(126)

文章存档

2012年(5)

2011年(3)

2010年(2)

2009年(116)

分类: LINUX

2009-02-20 07:36:50

1、  进程

a)         pid ——进程标识符

pid_t getpid()

pid_t getppid()

b)安全机制

       int setgroupssize_t num const gid_t *list

       int getgroupssize_t numgid_t *list

       int setreuiduid_t ruid uid_t euid

       int setregidgid_t rgid gid_t egid

       int setuiduid_t uid

       int setgidgid_t gid

       int seteuiduid_t uid

       int setegidgid_t uid

       uid_t getuid()

       uid_t geteuid()

       gid_t getgid()

       gid_t getegid()

c程序参数

       int mainint argc char * argv[]

       extern char *environ[]

       const char *getenvconst char *name

       int putenvconst char *string

       int setenvconst char *nameconst char *valueint overwrite

d)资源使用

       int getrusageint whostruct rusage *usage  #include

e)建立使用限制

       int getrlimitint resourcesstruct rlimit *rlim

       int setrlimintint resourcesconst struct rlimit *rlim

f)创建子进程

       #include

       pid_t fork()

g)等待子进程结束

       pid_t wait4pid_t pidint *statusint optionsstruct rusage *rusage

       pid_t waitint *status

       pid_t waitpidpid_t pidint *statusint options

       pid_t wait3int *statusint optionsstruct rusage *rusage

h)运行新程序

       int execlconst char *pathconst char * arg0

       int execlpconst char *fileconst char * arg0

       int execleconst char *pathconst char * arg0

       int execvconst char *pathconst char **arg

       int execvpconst char *fileconst char **arg

       int execveconst char *fileconst char **arg

i)                终止

void exitint exitcode

void _exitint exitcode

int killpid_t pidint signum

       j)简单子进程

              int systemconst char *cmd

              FIFE *popenconst char *cmdconst char *mode

              int pcloseFILE *stream

2、  文件管理

a)文件描述符

        stdinstdoutstderr

       b)文件操作

              int closeint fd         #include

              int openchar *pathnameint flagsmode_t mode

              int openchar *pathnamemode_t mode

              size_t readint fdvoid *bufsize_t length

              size_t writeint fdconst void *bufsize_t length

              int lseekint fdoff_t offsetint whence

                            SEEK_SET, SEEK_CUR, SEEK_END

              int truncateconst char *pathnamesize_tlength

              int ftruncateint fdsize_t length

              int fsyncint fd

              int fdatasyncint fd 

       c)查询和修改inode信息

              #include

              int statconst char *pathname struct stat * statbuf

              int lstatconst char *pathname struct stat * statbuf

int fstatint fd struct stat * statbuf

       d)测试访问权限

int accessconst char *pathnameint mode

                     F_OKR_OKW_OKX_OK

              #include

              int chmodconst char *pathnamemode_t mode

              int fchmodint fdmode_t mode

       eExt3扩展属性

              int ioctlint fd int requestvoid *arg

              EXT3_IOC_GETFLAGS, EXT3_IOC_SETFLAGS

       f)操作目录项

              int mknodconst char *pathnamemode_t modedev_t dev

                     S_IFIFOS_IFBLKS_IFCHAR

              Makedevmajorminor major()  minor()

              int linkconst char *origpathconst char *newpath     硬链接

              int symlinkconst char *origpathconst char *newpath)符号链接

              int readlinkconst char *pathnamechar *bufsize_t bufsize

              int unlinkchar *pathname

              int renameconst char *oldpathconst char *newpath

       g)操作文件描述符

              int fcntlint fdint commandlong arg

              int pipeint fds[2]

3、  信号处理

void *signalint signumvoid *handler

       SIG_IGNSIG_DFL              SIGKILLSIGSTOP

a)发送信号

       int tkillpid_t pidint signum

       int raiseint signum

       #include

       int sigemptysetsigset_t *set

       int sigfillysetsigset_t *set

       int sigaddysetsigset_t *setint signum

       int sigdelsetsigset_t *setint signum

       int sigismemberconst sigset_t *setint signum

              int sigactionint signumstruct sigaction *actstruct sigaction *oact

              int sigprocmaskint whatconst sigset_t *setsigset_t *oldset

                     SIG_BLOCKSIG_UNBLOCKSIG_SETMASK

              int sigpendingsigset_t *set

              int pausevoid

              int sigsuspendconst sigset_t *mask

              获取信号信息

              void handlerint signumsiginfo_t *siginfovoid *context

              struct sigaction{

                     union{

                            __sighandler_t sa_handler

                            __sigaction_t sa_sigaction

                     }

                     sigset_t sa_mask;

                     unsigned long sa_flags

              }

              si_signo

              si_codeSI_USERSI_QUEUESI_TKILLSI_KERNEL

              SIGSEGV       SEGV_MAPERR

                                   SEGV_ACCERR

              SIGBUS         BUS_ADRALN

                                   BUS_ADDERR

                                   BUS_OBJERR

              SIGCHLD      CLD_EXITED

                                   CLD_KILLED

                                   CLD_STOPPED

 

 

              void *sigqueuepid_t pidint signumconst union sigval value

              union sigval{

                     int sival_int

                     void *sival_ptr

              }

4、  高级文件操作

#include

int pollstruct pollfd *fdsint numfdsint timeout

struct pollfd{

        int fd

        short events

        short revents

}

        POLLINPOLLPRIPOLLOUTPOLLERRPOLLHUPPOLLNVAL

#include

int selectint numfdsfd_set *readfdsfd_set *writefdsfd_set *exceptfdsstruct timeval *timeout

FD_ZEROfd_set *fds                  FD_SETint fdfd_set *fds

FD_CLRint fdfd_set *fds         FD_ISSETint fdfd_set *fds

#include

int epoll_createint numDescriptors

int epoll_ctlint epfdint opint fdstruct epoll_event *event

int epoll_waitint epfdstruct epoll_event *eventsint maxeventsint timeout

5、  目录操作

char *getcwdchar *bufsize_t size

get_current_dir_name()

int chdirconst char *pathname

int fchdirint fd

int chrootconst char *path     chdir(“/”)

int mkdirconst char *dirnamemod_t mode

int rmdirconst char *pathname      ENOEMPTY

DIR *opendirconst char *pathname

int closedirDIR *dir

struct dirent *readdirDIR *dir              d_name  d_ino

int rewinddirDIR *dir

文件名匹配

int globconst char *patternint flagsint errfuncconst char *epathint eerrno),glob_t *pglob

typedef struct{

        int gl_pathc

        char **gl_pathv

        int gl_offs

}glob_t

int globerrconst char *pathnameint globerror

void globfreeglob_t *pglob

        GLOB_NOSPACE  GLOB_ABEND  GLOB_NOMATCH 

6、  Socket网络

#include

struct sockaddr{

        unsigned short sa_family

        char sa_data[MAXSOCKADDRDATA]

}

基本套接字操作

int socketint domainint typeint protocol

        domain:   PF_UNIX  PF_INET   PF_INET6

        type: SOCK_STREAM  SOCK_DGRAM  SOCK_RAW

        protocol: IPPROTO_ICMPIPPROTO_ICMPV6IPPROTO_IPIP

IPPROTO_IPV6IPPROTO_RAWIPPROTO_TCPIPPROTO_UDP

int bindint sockstruct sockaddr *my_addrsocklen_t addrlen

int listenint sockint baklog

int acceptint sockstruct sockaddr *my_addrsocklen_t *addrlen

int connectint sockstruct sockaddr *servaddrsocklen_t addrlen

int getpeernameint sstruct sockaddr *addrsocklen_t *addrlen

int getsocknameint sstruct sockaddr *addrsocklen_t *addrlen

 

Unix域套接字

#include

struct sockaddr_un{

        unsigned short sun_family

        char sun_path[UNIX_PATH_MAX]

}

UNIX_PATH_MAX = 108

阅读(2394) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~