-

- 加为好友
- 发送私信
- 在线聊天
-
yangzhifu
- 等级:

- 可用分等级:
- 总技术专家分:
- 总技术专家分排名:
- 揭帖率:
|
| 发表于:2008-08-23 17:51:37 楼主 |
文件描述符大开 - C/C++ code
#include <stdio.h>
#include <string.h>
int main()
{
int fd;
int pid;
char msg1[] = "Test 1 2 3 .. \n" ;
char msg2[] = "Hello.hello \n " ;
if (( fd = creat ("testfile" , 0644 )) == -1 )
return 0 ;
if ( write ( fd , msg1 , strlen(msg1) ) ==-1 )
return 0 ;
if ( ( pid = fork () ) == -1 )
return 0 ;
if ( write ( fd ,msg2 , strlen (msg2) ) == -1 )
return 0 ;
close ( fd ) ;
return 1 ;
}
结果 Test 1 2 3 .. Hello.hello Hello.hello 文件指针打开 - C/C++ code
#include <stdio.h>
#include <string.h>
int main()
{
FILE *fp;
int pid;
char msg1[] = "Test 1 2 3 .. \n" ;
char msg2[] = "Hello.hello \n " ;
if (( fp = fopen ("testfile2" , "w" )) == NULL )
return 0 ;
fprintf(fp,"%s",msg1 );
if ( ( pid = fork () ) == -1 )
return 0 ;
fprintf(fp,"%s",msg2 );
fclose ( fp ) ;
return 1 ;
}
结果 Test 1 2 3 .. Hello.hello Test 1 2 3 .. Hello.hello 为什么会有这样的不同? |
|
|
|
20
修改
删除
举报
引用
回复
| |