✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
Consider the two programs given below to implement the command (ignore the fact that error checks are not done on return values of functions)
$ ls . /tmp/asdfksdf >/tmp/ddd 2>&1
Program 1
int main(int argc, char *argv[]) { int fd, n, i; char buf[128]; fd = open("/tmp/ddd", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); close(1); dup(fd); close(2); dup(fd); execl("/bin/ls", "/bin/ls", ".", "/tmp/asldjfaldfs", NULL);}
Program 2
int main(int argc, char *argv[]) { int fd, n, i; char buf[128]; close(1); fd = open("/tmp/ddd", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); close(2); fd = open("/tmp/ddd", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); execl("/bin/ls", "/bin/ls", ".", "/tmp/asldjfaldfs", NULL);}Select all the correct statements about the programs