#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main(){
pid_t pid;
pid = fork();
if(pid<0){
fprintf(stderr, "fork failed");
return 1; }
else if(pid == 0){
execlp("bin/ls", "ls", NULL);}
else{
wait(NULL);
printf("child complete\n");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在我可以理解的情况下,创建了一个子进程,并且由于fork返回的pid为"0",它进入包含execlp的块并执行它,然后父进程等待子进程退出然后打印出"child complete" ".如果我错了,请纠正我.但我不明白execlp()在这里是如何工作的.有人可以解释一下吗?
有人可以在这里解释“ori”的用法吗?我知道它是按位或,但我不知道它是如何工作的,也不知道为什么这里需要它。
#objective of the program is to add 5 and 7
.data #variable declaration follow this line
.text #instructions follow this line
main:
ori $s0, $zero, 0x5
ori $s1, $zero, 0x7
add $t0, $s0, $s1
li $v0,10 # required for only QtSPIM
syscall # required for only QtSPIM
#end of program
Run Code Online (Sandbox Code Playgroud)