私の端末のファイル記述子は何ですか?

私の端末のファイル記述子は何ですか?

tcsetgrpバックグラウンドプロセスをフォアグラウンドプロセスにするには関数を使用する必要があります。引数は端末に関連付けられたtcsetgrpファイル記述子です。file descriptor私の端末またはそのint値は何ですか?

編集する

以下のコメントに基づいて、私のプログラムの一部を紹介します。

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<signal.h>
void sig_handler(int sig){

    printf("The grp get signal is  %d\n",tcgetpgrp(0));
}
int main(){

    printf("The controllling terminal is %d\n",tcgetpgrp(0));
    pid_t pid=fork();
    if(pid>0){
        signal(SIGINT,sig_handler);
        setpgid(pid,pid);
        tcsetpgrp(0,getpgid(pid));
        //tcsetpgrp(1,getpgid(pid));
        printf("Wait is over on %d",wait(NULL));
        tcsetpgrp(0,getpgid(getpid()));
        //tcsetpgrp(1,getpgid(getpid()));
        printf("The parent got control\n");
        while(1)
            //sleep(1);
            printf("Hello\n");

        return 0;
    }
    else{
        printf("The controllling terminal is %d\n",tcgetpgrp(0));
        printf("The controllling terminal is %d\n",tcgetpgrp(1));
        execlp("cat","cat",NULL);
    }
    return 0;

}

ここでは現在、catプログラムが前景であり、すべてがうまく機能しています。入力コンソールからデータを読み取り、それを出力コンソールに送信できます。しかし、私が押すとフォアグラウンドプロセスは終了しますが、後で述べたとしても、*cntrl-c*両親は端末を制御できません。私のシェルプロンプトが表示され、親プロセスはバックグラウンドプロセスのままです。tcsetpgrp(0,getpid())wait()

ベストアンサー1

プログラムでは、ファイル記述子0(stdin)、1(stdout)、および2(stderr)は、プログラムを呼び出すコマンドでリダイレクトまたはパイプを使用しない限り、デフォルトで端末に関連付けられます。

おすすめ記事