リーダー/ライターの問題をシミュレートする C プログラムで、複数の子プロセスを作成しました。各子プロセスは、 xtermウィンドウで別のプログラム (リーダーまたはライター) をfork()呼び出して実行します。execlp()
を終了するmain()と、xterm で実行されている子はまだ生きています。どうすればそれらも終了できますか?
以下のコードサンプル-
main() {
    while(1) {
    scanf(choice);
    switch(choice) {
        case 1: 
            reader()
            break;
        case 2: 
            writer();
            break;
        default:
            kill(getpgid(getpid()), SIGTERM); // killing the group id
            return 0;
        }
    }
reader() {
    /*
    some semaphore manipulation
    */
    execlp("xterm", "xterm", "-e", "./read", NULL);
    /*
    some semaphore manipulation
    */
    return 0;
    }
writer() {
    /*
    some semaphore manipulation
    */
    execlp("xterm", "xterm", "-e", "./write", NULL);
    /*
    some semaphore manipulation
    */
    return 0;
    }