Hi everyone, I have this assignment in which I need to run "ls" every N seconds. We're not allowed to use signals, we can only use the command sleep, but via an exec function, we can't use "system".
This is the code I have:
I've tried many things, but the problem is I have to run an execl (or execvp) with sleep in it. Being mandatory, it erases the rest of the program.Code:main() { int N=5; int i; pid_t pid; pid = fork(); if (pid==0) { for (i=0; i<N; i++) { if (fork()==0) execl("/bin/ls", "ls", NULL); } } else if (pid>0) { wait(NULL); } else perror("fork failed"); }
My teachers insists it can be done with execs, forks and waits. I still can't see how.