关于fork的个人理解
代码如下所示:
#include
#include
#include
#include
#include
#include void sig_child()
{
printf("child terminated\r\n");
}int main(int argc, const char *argv[])
{
int pipefd[2];
char buf[100]={0};
pid_t pid; // Create a pipe for interprocess communication
if(pipe(pipefd)<0)
{
perror("pipe");
exit(EXIT_FAILURE);
} // Create a process use fork
pid=fork(); if(pid > 0)
{
#if 0
printf("###id=[%d]###\n",pid);
printf("###pid=[%d]###\n",getpid());
printf("###ppid=[%d]###\n",getppid());
#endif
printf( "This is in the father process,here write a string to the pipe.\n" );
char buf[] = "Hello world , this is write by pipe.\n";
write( pipefd[1], buf, sizeof(buf) );
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
