|
CS 456 - Systems Programming
Spring 2024
|
Displaying ./code/feb08/exec2.c
#include <unistd.h>
#include <fcntl.h> // O_CREAT, O_APPEND etc. defined here
#include <stdio.h>
int main() {
close(1); // close standard out
open("log.txt", O_RDWR | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
puts("Captain's log");
chdir("..");
// execl( executable, arguments for executable including program name and NULL at the end)
execl("/bin/ls", /* Remaining items sent to ls*/ "/bin/ls", ".", (char *) NULL); // "ls ."
perror("exec failed");
return 0; // Not expected
}
|