나는 리눅스에서 프로세스를 만들려고하는데 오류가 계속 발생한다. 내 C++ 코드에서 firefox.exe를 열고 싶다. 내 코드는 다음과 같습니다.리눅스에서 프로세스를 만드는 방법
//header files
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
//main function used to run program
int main()
{
//declaration of a process id variable
pid_t pid;
//fork a child process is assigned
//to the process id
pid=fork();
//code to show that the fork failed
//if the process id is less than 0
if(pid<0)
{
fprintf(stderr, "Fork Failed");// error occurred
exit(-1); //exit
}
//code that runs if the process id equals 0
//(a successful for was assigned
else if(pid==0)
{
//this statement creates a specified child process
execlp("usr/bin","firefox",NULL);//child process
}
//code that exits only once a child
//process has been completed
else
{
wait(NULL);//parent will wait for the child process to complete
cout << pid << endl;
printf("Child Complete");
exit(0);
}
}
wait() 함수에 오류가 있습니다. 나는 이것을 버리고 시도했지만, 아무 일도 일어나지 않았다.
execlp()에 오류가 있는지 확인한 다음 자식이 종료되도록하려면 어떻게됩니까? – pilcrow