rasperry Pi で omxplayer のリモート コントロール プログラムを作成しようとしています。
子プロセスで omxplayer を正常に実行させることはできますが、実際にコマンドを子プロセスに送信するためにパイプを正しく動作させることができないようです。
int fd_pipe[2];
pipe (fd_pipe);
while(1) { // main accept() loop
printf("server: got connection from %s\n", s);
/* Attempt to fork and check for errors */
if( (pid=fork()) == -1){
fprintf(stderr,"Fork error. Exiting.\n"); /* something went wrong */
exit(1);
}
if (pid==0)
{ // this is the child process
dup2(0, fd_pipe[0]);
close(fd_pipe[1]);
if(execl("/usr/bin/top","top",NULL) == -1){
fprintf(stderr,"execl Error!");
exit(1);
}
//try and send command here
write(fd_pipe[0], "q", 1);
exit(0);
} else {
close(new_fd); // parent doesn't need this
dup2(1, fd_pipe[1]);
//try and send here too
write(fd_pipe[0], "q", 1);
}
}
top でテストしてプログラムを実行すると、ターミナル ウィンドウに top の出力が表示され、ウィンドウに q コマンドが表示されますが、子プロセスではなく親プロセスに移動しているように見えます。パイプに何か問題がありますか、それとも生成された子プロセスにコマンドを送信できませんか?
子の dup2 ステートメントをパイプから stdin にコピーするように変更してみました
{ // this is the child process
dup2(fd_pipe[0], 0);
しかし、トップは失敗した tty get メッセージで起動に失敗します