码迷,mamicode.com
首页 > 其他好文 > 详细

Unix环境高级编程

时间:2016-04-29 07:01:55      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

一. 进程

C编译器(gcc)——>连接编辑器— (设置起始地址:启动例程)—>可执行程序文件—(启动例程)—>内核(命令行参数、环境变量值)

            ——>main()—(大多数)—>exit()——>_exit()【or _Exit()】

 1. exit

#include <stdlib.h>          
void exit(int status);
void _Exit(int status);

#include <unistd.h>
void _exit(int status);

 

 2. atexit  :  登记终止处理程序

#include <stdlib.h>
int atexit(void (*func)(void));
//return: success, 0; error, other.

 

3. 存储器分配

#include <stdlib.h>
void *malloc(size_t size);
void *calloc(size_t nobj, size_t size);
void *realloc(void *ptr, size_t newsize);

//return: success, 非空;error, NULL.

void free(void *ptr);

 

 4. 环境变量

 

#include <stdlib.h>
char *getenv(const char *name);

//return: 与 name 关联的指针,未找到则 NULL.

int putenv(char *str);
int setenv(const char *name, const char *value, int rewrite);
int unsetenv(const char *name);

//return: success, 0; error, 非0. 

 

5. setjmp & longjmp

#include <setjmp.h>
int setjmp(jmp_buf env);

//return: 直接返回,0; 从 longjmp 调用返回则 非0.

void longjmp(jmp_buf env, int val);

 

6. getrlimit & setrlimit

#include <sys/resource.h>
int getrlimit(int resource, struct rlimit *rlptr);
int setrlimit(int resource, const struct rlimit *rlptr);

//return: success, 0; error, 非0.

 

 

 

二.线程

#include <pthread.h>

int pthread_equal (pthread_t tid1, pthread_t tid2); //return: S, 0; E, 非0.

pthread_t pthread_self (void); // return ID.

int pthread_create (pthread_t *restrict tidp, const pthread_attr_t *restrict attr, 
                         void *(*start_rtn)(void), void *restrict arg);
//return: S, 0; E, 错误编号.

void pthread_exit(void *rval_ptr);

int pthread_join(pthread_t thread, void **rval_ptr); //return: S, 0; E, 错误编号.

int pthread_cancel(pthread_t tid);  //return: S, 0; E, 错误编号.

void pthread_cleanup_push(void (*rtn)(void *), void *arg);
void pthread_cleanup_pop(int execute);

int pthread_detach (pthread_t tid);  //return: S, 0; E, 错误编号.

int pthread_mutex_init (pthread_mutex_t *restrict mutex, 
                                  const pthread_mutexattr_t *restrict attr);
int pthread_mutex_destroy (pthread_mutex_t *mutex);
//return: S, 0; E, 错误编号.

int pthread_mutex_lock (pthread_mutex_t *mutex);
int pthread_mutex_trylock (pthread_mutex_t *mutex);
int pthread_mutex_unlock (pthread_mutex_t *mutex);
//return: S, 0; E, 错误编号.

int pthread_rwlock_init (pthread_rwlock_t *restrict rwlock, 
                                  const pthread_rwlockattr_t *restrict attr);
int pthread_rwlock_destroy (pthread_rwlock_t *mutex);
//return: S, 0; E, 错误编号.

int pthread_rwlock_rdlock (pthread_rwlock_t *rwlock);
int pthread_rwlock_wrlock (pthread_rwlock_t *rwlock);
int pthread_rwlock_unlock (pthread_rwlock_t *rwlock);
//return: S, 0; E, 错误编号.

int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
//return: S, 0; E, 错误编号.

int pthread_cond_init (pthread_cond_t *restrict cond, 
                                  const pthread_condattr_t *restrict attr);
int pthread_cond_destroy (pthread_cond_t *cond);
//return: S, 0; E, 错误编号.

int pthread_cond_wait (pthread_cond_t *restrict cond,
                                pthread_mutex_t *restrict mutex);
int pthread_cond_timedwait (pthread_cond_t *restrict cond,
                                pthread_mutex_t *restrict mutex,
                                const struct timespec *restrict timeout);
//return: S, 0; E, 错误编号.

int pthread_cond_signal (pthread_cond_t *cond);
int pthread_cond_broadcast (pthread_cond_t *cond);
//return: S, 0; E, 错误编号.

 

Unix环境高级编程

标签:

原文地址:http://www.cnblogs.com/liyangguang1988/p/5444946.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!