如何解决c语言fork进程无需等待子进程
我在c语言做fork练习的时候有个问题,很简单:
<!-- Block for the Calendar -->
<div class="calendar">
<label>From Date</label>
<input type="date" name="" max="" id="fromDate">
<br><br>
<label>To Date</label>
<input type="date" name="" max="" id="toDate">
<br><br>
<button onclick="myFunction()">See Data</button>
</div>
<p id="selectedDate"></p>
<!-- Block for Calendar to show error-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script type="text/javascript">
var fromDate;
$('#fromDate').on('change',function(){
fromDate = $(this).val();
$('#toDate').val(""); // RESET toDate when fromDate is changed
$('#toDate').prop('min',function(){
return fromDate;
})
});
</script>
<!-- Storing the Value of the fromDate and toDate -->
<script>
var dateDict = {
"2021-04-01": 1,"2021-04-02": 1,"2021-04-03": 5,"2021-04-04": 1,"2021-04-05": 2
};
function myFunction() {
var x = document.getElementById("fromDate").value;
var y = document.getElementById("toDate").value;
document.getElementById("selectedDate").innerHTML = x + y;
console.log(fromDate in dateDict); // gives true if fromDate is in dateDict
console.log(dateDict[fromDate]); // gives the value corresponding to the date
}
</script>
输出不是我所期望的:
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
// forkexec.c: fork then exec
int
main()
{
int pid;
pid = fork();
if(pid == 0){
char *argv[] = { "echo","THIS","IS","ECHO",0 };
execvp("echo",argv);
printf("exec failed!\n");
exit(1);
} else {
printf("parent waiting\n");
//wait(&status);
//printf("the child exited with status %d\n",status);
}
exit(0);
}
怎么可能?似乎在 THIS IS ECHO 之后仍然等待用户输入,多么神奇的等待!它会导致程序无法正常运行!所以有人可以解释一下吗?谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。