Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

T2: Write a program that lists down at least three different system calls of lin

ID: 3620951 • Letter: T

Question

T2: Write a program that lists down at least three different system calls of linux and allows the user to select any one of them to execute using your program.

· Once you take input from the user create a new process from within your process and use it to execute this system call taken as input from the user.

· Your program should not exit and allow the user to select new commands and run them until he gives the input "quit" to quit your program.

· Note that you may require the use of fork and exec to accomplish this task

please help me out.........

Explanation / Answer

#include #include #include #include #include int main(int argc, char *argv[]) { int status; int pid; char cmd[100]; int n; /* * Build argument list */ while(1) { printf("Enter choice:1.ls 2.pwd 3./sbin/ifconfig otherwise. Exit "); scanf("%d",&n); switch(n) { case 1: strcpy(cmd,"ls"); break; case 2: strcpy(cmd,"pwd"); break; case 3: strcpy(cmd,"/sbin/ifconfig"); break; case 4: exit(0); break; } /* * Create a process space for cmd */ if ((pid=fork()) < 0) { perror ("Fork failed"); exit(errno); } if (!pid) { /* This is the child, so execute the ls */ printf(" #####################Child process output########################## "); system(cmd); printf(" ################################################################## "); exit(0); } if (pid) { /* * We're in the parent; let's wait for the child to finish */ waitpid (pid, NULL, 0); } } }