flush.c

来自「基于socket的简单通讯程序」· C语言 代码 · 共 60 行

C
60
字号
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#define SIZBUF 15

int main(void)

{
	char output[SIZBUF];
	pid_t pid,wpid;
	int wstatus;
	FILE *fp;
	
	printf("Content-Type:text/html\n\n");
   	printf("<head><title>AnHTMLPageFromaCGI</title></head>\n");
	printf("<body><br>\n");	
	printf("<H3>The Picture is as follows</H3>");

	pid = vfork ();

	if (pid < 0) {
		printf("fork: %m");
		wstatus = 0;
	} else if (pid) {
		do {
			wpid = wait (&wstatus);
		} while (wpid != pid && wpid > 0);
		if (wpid < 0) {
			printf("wait: %m");
			wstatus = 0;
		}
	} else {

		execl ("readsimple", "readsimple",(char*)0);
		printf("error execl return");
		exit (0);
	}
	printf("<p>vfork is finished!I am in parent pid</P>");

	fp=fopen("/home/www/out.dat","r");
	if(fp==NULL){
		printf("ERROR!Cannot open file !\n");
	}
	
	printf("<p>\n");
	while((fgets(output,SIZBUF,fp))!=NULL)
		printf("%s",output);
		
	printf("</p>\n");
	
	printf("</body>\n");
	printf("</html>\n");  
//	printf("\n<img src=\"/pic/shuai.gif\">\n");
	
	
   return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?