<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/156484>156484</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [lit] Internal shell will hang when fork outlives parent with a file descriptor
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            boomanaiden154
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          boomanaiden154
      </td>
    </tr>
</table>

<pre>
    If we take the minimal following c program:
```
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <time.h>

int main() {
    int test = fork();
 if (test == 0) {
        printf("Exiting parent\n");
        return 0;
 } else if (test > 0) {
        struct timespec test5 = {1, 0};
 int fd = open("/tmp/test10", O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
 nanosleep(&test5, NULL);
        write(fd, "test", 4);
 write(fd, "test", 4);
        close(fd);
    }
    printf("Exiting fork\n");
    exit(0);
    return 0;
}
```

and try to execute it with lit using the internal shell with a test file like the following:
```
// RUN: %clang %S/test.c -o %t.exe
// RUN: %t.exe
```

lit will end up hanging in a `Popen.communicate()` call for unknown reasons. A workaround for now is to just invoke the test with bash and have a wait call:
```
// RUN: %clang %S/test.c -o %t.exe
// RUN: bash -c "%t.exe; wait"
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0VV9r4zgQ_zTKy9Agy3_z4Ie0aaBQukd6ZbmnotjjWFtZMtK4ab_9IcVtN7dZuJcVIRHz-43m_0R6rw4GsWb5NRNib-0gjVQtmiTPmBAs3yzkRL119Tm22Nv2vb7r4IhA8gWBeoRBGTVIDZ3V2h6VOUADo7MHJweWrhlfs4LPH75mIlWm0VOLwNKbrjGklz1Lb3-BPLXK_hbSan8Zm4zy1P5G790zsT1KRZdxUgN-InytDMEglWGiYmIFrLxmfA0AEABCT8DSDXTWvZwYLI0E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