Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
Modify the program exec_in.c to obtain the same result but replacing the functions sleep and system for system calls. You can use exit, exec*, pause, alarm, etc. The new program will be called exec_in2.c and keep the original program sintaxi
2. Relevant commands, code, scripts, algorithms:
3. The attempts at a solution (include all code and scripts):
I'm not sure what system call I need to solve the problem, I think that I need to use alarm but I don't know how to use correctly that, I never used system calls in C before, also I have only been using linux one week and I'm really lost.
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course): Centre d'estudis Roca, Barcelona, Spain, Mariano Torres
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
I use ubuntu 12.04 64 bits
1. The problem statement, all variables and given/known data:
Modify the program exec_in.c to obtain the same result but replacing the functions sleep and system for system calls. You can use exit, exec*, pause, alarm, etc. The new program will be called exec_in2.c and keep the original program sintaxi
2. Relevant commands, code, scripts, algorithms:
Code:
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <unistd.h> #include "rutines.h" int main(int argc, char *argv[]) { char cmd[256]; int a; if (argc<2) Error("Insufficient arguments: exec_in <sec> <cmd> [args...]"); sleep(atoi(argv[1])); cmd[0]='\0'; for(a=2;a<argc;a++) { strcat(cmd,argv[a]); strcat(cmd," "); } system(cmd); exit(0); }
3. The attempts at a solution (include all code and scripts):
I'm not sure what system call I need to solve the problem, I think that I need to use alarm but I don't know how to use correctly that, I never used system calls in C before, also I have only been using linux one week and I'm really lost.
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course): Centre d'estudis Roca, Barcelona, Spain, Mariano Torres
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
I use ubuntu 12.04 64 bits