fflash函数、strtok函数exec函数

一、fflush函数
函数定义:int fflush(FILE *stream);
1.fflush会强迫将缓冲区内的数据回写到参数stream指向的文件中,如果参数stream为NULL,fllush会将所有打开的文件数据更新
2.fflush(stdin)刷新缓冲区,把缓冲区中的东西丢掉。 fflush(stdout)将缓冲区中的东西输出到设备中去。

二、字符串切割函数strtok()
函数定义:char *strtok(char *s, const char *delim);
eg:将cmd指向的字符串按空格分开,并存入argv中
void CutCmd(char *cmd, char **argv)
{
int count = 0;
char *p = strtok(cmd, ” “);
while(p != NULL)
{
argv[count++] = p;
p = strtok(NULL, ” “);
}
}

三、exec系列函数
1.函数说明:fork函数是用于创建一个子进程,该子进程几乎是父进程的副本,而有时我们希望子进程去执行另外的程序,exec函数族就提供了一个在进程中启动另一个程序执行的方法。它可以根据指定的文件名或目录名找到可执行文件,并用它来取代原调用进程的数据段、代码段和堆栈段,在执行完之后,原调用进程的内容除了进程号外,其他全部被新程序的内容替换了。另外,这里的可执行文件既可以是二进制文件,也可以是Linux下任何可执行脚本文件。
2.函数原型:
int execl(const char path, const char *arg, …, (char )0)
int execv(const char *path, char *const argv[])
int execle(const char path, const char *arg, …, (char )0, char *const envp[])
int execve(const char *path, char *const argv[], char *const envp[])
int execlp(const char *file, const char *arg, …)
int execvp(const char *file, char *const argv[])
函数成功不返回, 失败返回-1。

猜你喜欢

转载自blog.csdn.net/D_o_nlyone/article/details/82528052