我正在执行以下程序,在其中创建各种过程,就像它们是二叉树一样,我希望“左边”的孩子与“右边”的孩子做不同的事情,但它向我输出了两个孩子在右边或左边有2个孩子,我不想要那个。
void slice(int dir){
if (dir == 1) {
printf("izq ");
printf("child pid %d parent pid %d\n",getpid(),getppid());fflush(stdout);
}
else if (dir == 2){
printf("der ");
printf("child pid %d parent pid %d\n",getpid(),getppid());fflush(stdout);
}
}
void vector(int vector[], int length, int niveles){
for(int i=1;i<=niveles;i++)
{
int error = 0;
pid_t child_pid[2] = { -1, -1 };
for (int dir=0; dir<=1; ++dir) {
child_pid[dir] = fork();
if (child_pid[dir] == -1) {
error = 1;
perror("fork");
}
if (child_pid[dir] == 0) {
// Here is where you place the code the child should execute.
slice(dir);
exit(0);
}
}
for (int dir=0; dir<=1; ++dir) {
if (child_pid[dir] == -1)
continue;
int status;
pid_t pid = waitpid(child_pid[dir], &status, 0);
if (pid == -1) {
error = 1;
perror("waitpid");
}
else if (WIFSIGNALED(status)) {
error = 1;
fprintf(stderr, "Child was killed by signal %d\n", WTERMSIG(status));
}
else if (WEXITSTATUS(status) != 0) {
error = 1;
fprintf(stderr, "Child exited with error %d\n", WEXITSTATUS(status));
}
}
if (error)
exit(1);
}
}
我的目标是为“ izq”调用一个函数,该函数在保持整个二叉树概念的同时,与“ der”有所不同。
答案 0 :(得分:0)
请记住,父级和子级都从 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="projects">
<h1 id="project" class="pro">Projects</h1>
<div class="flex-container">
<div class="container-fluid p-0 d-flex justify-content-center d-inline align-content-center">
<div class="row ">
<div class="col-6 col-sm-2" >
<div class="one" style="width: 285px; height: 275px;">
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front">
<img class="light" src="light.png">
</div>
<div class="flip-card-back">
<h1>John Doe</h1>
<p>Architect & Engineer</p>
<p>We love that guy</p>
</div>
</div>
</div> </div> </div>
<div class="two"style="width: 299px; height: 275px;">
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front t2">
<img class="light" src="light.png">
</div>
<div class="flip-card-back">
<h1>John Doe</h1>
<p>Architect & Engineer</p>
<p>We love that guy</p>
</div>
</div> </div>
</div></div>
<div class="three "style="width:285px; height:275px; ">
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front t3">
<img class="light" src="light.png">
</div>
<div class="flip-card-back">
<h1>John Doe</h1>
<p>Architect & Engineer</p>
<p>We love that guy</p>
</div>
</div> </div>
</div></div>
<div class="container-fluid p-0 d-flex align-content-center justify-content-center d-inline ">
<div class="row ">
<div class="col-6 col-sm-2" >
<div class="four"style="width: 285px; height:275px;">
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front t4">
<img class="light" src="light.png">
</div>
<div class="flip-card-back">
<h1>John Doe</h1>
<p>Architect & Engineer</p>
<p>We love that guy</p>
</div>
</div> </div>
</div></div>
<div class="five"style="width: 299px; height:275px;">
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front t5">
<img class="light" src="light.png" >
</div>
<div class="flip-card-back">
<h1>John Doe</h1>
<p>Architect & Engineer</p>
<p>We love that guy</p>
</div>
</div>
</div></div></div>
<div class="six"style="width: 285px; height:275px;">
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front t6 ">
<img class="light" src="light.png">
</div>
<div class="flip-card-back">
<h1>John Doe</h1>
<p>Architect & Engineer</p>
<p>We love that guy</p>
</div>
</div></div></div></div></div>
</div>
开始执行,因此您需要执行以下操作:
select phone_number from table1;
result
1234567880
desired result
+11234567880