Linux C文件操作(二)
来源:互联网 发布:lvs keepalived nginx 编辑:程序博客网 时间:2024/05/16 16:13
1.getpid()
函数的作用: 获得进程的识别号
函数的原型: pid_t getpid(void);
返回值:当前进程的识别号;
头文件: #include <unistd.h>
2. fork
函数的作用:创建一个进程,
函数的原型: pid_t fork(void);
函数的返回值:<0 , 出错
=0 子进程
>0 父进程 ----这个值是子进程的进程号
子进程把父进程的资源基本拷贝了一份,
3. vfork
函数的作用:建立一个新的进程
函数的原型: pid_t vfork()
函数的返回值: <0,出错
=0 ,子进程
>0, 父进程
两者区别:
4. execl
函数的作用:执行文件
函数的原型:int execl(const char * path, const char *arg);
函数的参数: path:字符串代表的文件路径,
argv[]:执行文件传递的参数地址,
最后一个以NULL结束;
返回值:成功不返回,失败-1;
5.execv
函数的作用:执行文件
函数的原型: int execv(const char *ptah, char *const argv[]);
函数的参数: path:字符串代表的文件路径;
argv:数组指针;
返回值: 成功不返还,出错-1;
7.system
函数的作用; 执行命令
函数的原型:int system(const char *string);
函数的参数:string:代表的命令字符串;
返回值:
头文件:#include <stdlib.h>
8.wait
函数的功能:等待子进程中断或结束
函数的原型:pid_t wait(int *status);
函数说明: 暂停目前进程,直到有信号来或子进程结束。如果调用wait时已经结束,会
立即返回。
返回值:成功则返回子进程pid号,出错-1;
头文件:#include <sys/types.h>
#include <sys/wait.h>
10.waitpid
函数的功能:等待子进程中断或者结束
函数的原型:pid_t waitpid(pid_t pid, int *status, int options);
函数的参数:pid :
<-1, 等待进程识别码为pid绝对值的任何子进程;
=-1, 等待任何子进程,=wait();
=0, 等待进程组识别码与目前进程相同的任何子进程;
>0, 等待进程号为pid的子进程;
options:
WNOHANG:没有子进程退出马上返回,不等待;
WUNTRACED: 如果子进程进入暂停执行状况则,马上返回,结束状态不予厉害:
返回值:
执行成功返回子进程的PID,出错-1;
如果使用WNOHANG无子进程退出则返回0;
11.exit _exit
exit:
函数的作用:正常结束进程
函数的原型:void exit(int status);
头文件: #include <stdlib.h>
_exit()
h函数的作用:结束进程执行;
函数的原型: void _exit(int stauts);
头文件: #include <unistd.h>
两个区别:_exit: 直接使进程停止,清除使用的内存,并清除缓冲区的内容;
exit:在停止之前,检查文件的打开,把缓冲区的内容写回文件才停止进程。
12. pipe
函数的功能: 建立管道;
函数的原型: int pipe(int fd[2]);
函数的 参数: fd[0]:用于读管道;
fd[1]:用于写管
返回值: 成功0,出错-1;
fork和pipe是顺序?
fork? pipe?
先pipe 后fork:
13.mkfifo
函数的作用:建立有名管道
函数的原型:int mkifo(const char * pathname, mode_t mode);
函数的参数:pathname:管道文件;
mode:管道文件的权限
返回值:成功0,出错-1;
头文件: #include <sys/types.h>
#include <sys/stat.h>
管道的操作:
创建管道mkfifo;
打开管道open
读管道read
写管道write
关闭管道close
删除管道unlink
函数的作用: 获得进程的识别号
函数的原型: pid_t getpid(void);
返回值:当前进程的识别号;
头文件: #include <unistd.h>
2. fork
函数的作用:创建一个进程,
函数的原型: pid_t fork(void);
函数的返回值:<0 , 出错
=0 子进程
>0 父进程 ----这个值是子进程的进程号
子进程把父进程的资源基本拷贝了一份,
3. vfork
函数的作用:建立一个新的进程
函数的原型: pid_t vfork()
函数的返回值: <0,出错
=0 ,子进程
>0, 父进程
两者区别:
4. execl
函数的作用:执行文件
函数的原型:int execl(const char * path, const char *arg);
函数的参数: path:字符串代表的文件路径,
argv[]:执行文件传递的参数地址,
最后一个以NULL结束;
返回值:成功不返回,失败-1;
5.execv
函数的作用:执行文件
函数的原型: int execv(const char *ptah, char *const argv[]);
函数的参数: path:字符串代表的文件路径;
argv:数组指针;
返回值: 成功不返还,出错-1;
7.system
函数的作用; 执行命令
函数的原型:int system(const char *string);
函数的参数:string:代表的命令字符串;
返回值:
头文件:#include <stdlib.h>
8.wait
函数的功能:等待子进程中断或结束
函数的原型:pid_t wait(int *status);
函数说明: 暂停目前进程,直到有信号来或子进程结束。如果调用wait时已经结束,会
立即返回。
返回值:成功则返回子进程pid号,出错-1;
头文件:#include <sys/types.h>
#include <sys/wait.h>
10.waitpid
函数的功能:等待子进程中断或者结束
函数的原型:pid_t waitpid(pid_t pid, int *status, int options);
函数的参数:pid :
<-1, 等待进程识别码为pid绝对值的任何子进程;
=-1, 等待任何子进程,=wait();
=0, 等待进程组识别码与目前进程相同的任何子进程;
>0, 等待进程号为pid的子进程;
options:
WNOHANG:没有子进程退出马上返回,不等待;
WUNTRACED: 如果子进程进入暂停执行状况则,马上返回,结束状态不予厉害:
返回值:
执行成功返回子进程的PID,出错-1;
如果使用WNOHANG无子进程退出则返回0;
11.exit _exit
exit:
函数的作用:正常结束进程
函数的原型:void exit(int status);
头文件: #include <stdlib.h>
_exit()
h函数的作用:结束进程执行;
函数的原型: void _exit(int stauts);
头文件: #include <unistd.h>
两个区别:_exit: 直接使进程停止,清除使用的内存,并清除缓冲区的内容;
exit:在停止之前,检查文件的打开,把缓冲区的内容写回文件才停止进程。
12. pipe
函数的功能: 建立管道;
函数的原型: int pipe(int fd[2]);
函数的 参数: fd[0]:用于读管道;
fd[1]:用于写管
返回值: 成功0,出错-1;
fork和pipe是顺序?
fork? pipe?
先pipe 后fork:
13.mkfifo
函数的作用:建立有名管道
函数的原型:int mkifo(const char * pathname, mode_t mode);
函数的参数:pathname:管道文件;
mode:管道文件的权限
返回值:成功0,出错-1;
头文件: #include <sys/types.h>
#include <sys/stat.h>
管道的操作:
创建管道mkfifo;
打开管道open
读管道read
写管道write
关闭管道close
删除管道unlink
0 0
- Linux C文件操作(二)
- Linux-C高级编程(1)文件操作(二)
- Linux C 学习之文件操作(二)
- linux c 编程实战:文件操作总结(二)
- Linux文件操作(二)
- Linux文件操作(二)
- Linux 命令行操作(二)文件操作
- 复习linux C编程(二)之 linux 常用文件操作命令
- C#XML文件操作类(二)
- linux c 文件操作
- Linux C 文件操作
- 【LINUX C】文件操作
- Linux C 文件操作
- Linux C 文件操作
- Linux下C编程入门笔记——文件IO操作(二)
- C拾遗(五)Linux文件操作
- Linux C文件操作(一)
- Linux C文件操作(三)
- IDEA license server 激活
- [数论] BZOJ2440 完全平方数
- webpack的使用以及脱坑集合
- 数学黑洞 (sdut oj)
- Vue的条件渲染
- Linux C文件操作(二)
- 《Image-to-Image Translation with Conditional Adversarial Networks》论文笔记
- 使用JUnit4测试Spring
- android7.0 多渠道打包和gradle打包常见问题
- gcc 编译relocation相关的一个问题
- 哦.我只是想说…我曾入坑iOS
- celery 4.0不支持windows系统:OSError: [WinError 87] 参数错误
- LeetCode
- SCALA FUNCTION STYLE