#include
#include
#include
#include
#include
int main(int argc, char* argv[])
{
int fd = open("tmp.txt", O_CREAT | O_APPEND | O_RDWR, 0666);
char buf[] = "hello huang jia jia\n";
write(fd, buf, sizeof(buf));
close(fd);
sleep(8);
if(fork() == 0)
{
if(execl("a.out", NULL) < 0)
{
perror("Execl:");
}
}
return 0;
}
关闭进程命令:ps l | grep out | grep -v grep | cut -d' ' -f6 | xargs kill -9

本文展示了一个简单的C语言程序示例,该程序用于创建一个名为tmp.txt的文本文件,并向其中写入特定字符串。此外,程序还演示了如何使用fork()创建子进程并执行另一个程序a.out。
269






