这个C 程序怎么会 什么都不输出。
C/C++ code:
]#include <unistd.h>
#include <signal.h>
#include <stdio.h>
int pid1,pid2;
int main( ) {
int fd[2];
char OutPipe[100],InPipe[100]; // 定义两个字符数组
pipe(fd); // 创建管道
while((pid1 = fork( )) == -1); // 如果进程1创建不成功,则空循环
if(pid1 == 0) {
lockf(fd[1],1,0); // 锁定管道
sprintf(OutPipe,"\n Child process 1 is sending message!\n");
write(fd[1],OutPipe,50); // 向管道写入数据
sleep(5); // 等待读进程读出数据
lockf(fd[1],0,0); // 解除管道的锁定
exit(0); // 结束进程1
}
else {
while((pid2 = fork()) == -1); // 若进程2创建不成功,则空循环
if(pid2 == 0) {
lockf(fd[1],1,0);
sprintf(OutPipe,"\n Child process 2 is sending message!\n");
write(fd[1],OutPipe,50);
sleep(5);
lockf(fd[1],0,0);
exit(0);
}
else {
wait(0); // 等待子进程1 结束
read(fd[0],InPipe,50); // 从管道中读出数据
相关问答:
#include <stdio.h>
#include <graphics.h>
void main()
{
int x0,y0,x1,y1,driver,mode,i;
driver=VGA;
mode=VGAHI;
initgraph(&driver,&mode,&qu ......
问一下:
#include <stdio.h>
int main()
{
char x, y, z;
int i;
int a[16];
for(i=0; i<=16; i++)
{
a[i] = 0;
......
现在有关c++、c的书籍,那些书是较深层次的?请介绍几本?
#include <iostream>
using namespace std;
int funhion(int x, int y )
{
int m,n;
  ......
1. 如下定义会有什么错误发生
//file1.c
int a[10];
//file2.c
extern int *a;
2. 大容量全局变量有什么危害,如
//file.c
......
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<c:forEach items="${quaeres}" var="q">
......