Week 08 Lab 02_____ (1)

.docx

School

University of Texas, Dallas *

*We aren’t endorsed by this school

Course

3377

Subject

Computer Science

Date

May 8, 2024

Type

docx

Pages

9

Uploaded by CoachSparrowMaster99 on coursehero.com

Week 08 Lab 02 Muhammad login as: axm210331 Pre-authentication banner message from server: | University of Texas at Dallas | Department of Computer Science | | Use of UTD Information Systems is subject to | the UTD Information Security and Acceptable Use Policy. | | Pursuant to Texas Administrative Code 202: | (1) Unauthorized use is prohibited; | (2) Usage may be subject to security testing and monitoring; | (3) Misuse is subject to criminal prosecution; and | (4) No expectation of privacy except as otherwise provided by applicable | privacy laws. | | ATTENTION: utdnetid != utdnetid@utdallas.edu (UTD != Google!) | | Just use utdnetid, and for the love of programming, STOP USING ALL CAPS! | | [[NOTE: All CS Graduate Students should use csgrads1.utdallas.edu ]] | [[ If you are a CS Graduate Student, you cannot logon to this server.]] | | | ***** This system will require a connection to the GlobalProtect VPN startin > g | on the following dates: | | cslinux1.utdallas.edu - June 15, 2020 | cslinux2.utdallas.edu - June 22, 2020 | | ***** GlobalProtect VPN Instructions: https://www.utdallas.edu/oit/howto/vpn > / | End of banner message from server Keyboard-interactive authentication prompts from server: End of keyboard-interactive prompts from server +----------------------------------------------------------------------+ MobaXterm Personal Edition v23.2 (SSH client, X server and network tools) ? SSH session to axm210331@cslinux1.utdallas.edu
Direct SSH : ? SSH compression : ? SSH-browser : ? X11-forwarding : ? (remote display is forwarded through SSH) ? For more info, ctrl+click on help or visit our website. +----------------------------------------------------------------------+ Last login: Fri Oct 20 23:52:25 2023 from 10.50.240.241 ***---***---***---***---***---*** csgrads1.utdallas.edu - CentOS Linux 7.9 --All CS Graduate Students should use csgrads1-- cs1.utdallas.edu - CentOS Linux 7.9 cs2.utdallas.edu - CentOS Linux 7.9 ***---***---***---***---***---*** This system is for use by CS students who need a general purpose Linux system to complete homework assignments. Computationally or resource intensive simulations will be throttled automatically. Thank you, CS Lab Manager cs-labs@utdallas.edu /scratch disk space can be used for temporary files. All files within /scratch will be erased on a regular basis (Sunday 0300). {cslinux1:~} whoami axm210331 {cslinux1:~} ls abc.txt dog lab1 pwd w5l1 Week05Lab2 week5lab1 a.out first.txt lab2 sample.txt w5l2 week07Lab1 welcome.c apue hello lab3 scriptForNew w6l1 week07Lab2 welcome.h cat.txt hello(2).c Makefile script.sh w7l1 week08Lab01 welcome.h.gch ch4lab1 hello(3).c new.txt short w7l2 week09Lab01 ch4lab2 hello.c perl5 typescript Week05Lab1 week09Lab02 data.txt hey practice Untitled.txt Week05Lab12 Week4Lab1 days hey.txt public_html w4l1 Week05Lab13 week4lab2 {cslinux1:~} cd week08Lab02 {cslinux1:~/week08Lab02} ls {cslinux1:~/week08Lab02} script w8l2 Script started, file is w8l2 {cslinux1:~/week08Lab02} ls tryShell.c
ls: cannot access tryShell.c: No such file or directory {cslinux1:~/week08Lab02} ls w8l2 {cslinux1:~/week08Lab02} cd ../ {cslinux1:~} ls tryShell.c tryShell.c Part 1 {cslinux1:~} mv tryShell.c week08Lab02 {cslinux1:~} cd week08Lab02 {cslinux1:~/week08Lab02} ls tryShell.c w8l2 a)tryShell receive + open {cslinux1:~/week08Lab02} cat tryShell.c /* source: www.csl.mtu.edu/cs4411.ck/www/NOTES/process/fork/exec.html */ #include <stdio.h> #include <sys/types.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #define MAX 1024 void parse(char *line, char **argv) { while (*line != '\0') { /* if not the end of line */ while (*line == ' ' || *line == '\t' || *line == '\n') *line++ = '\0'; /* replace white spaces with 0*/ *argv++ = line; /* save the argument position */ while (*line != '\0' && *line != ' ' && *line != '\t' && *line != '\n') line++; /* skip the argument until ... */ } *argv = '\0'; /* mark the end of argument list */ } void execute(char **argv) { pid_t pid; int status;
if ((pid = fork()) < 0) { /* fork a child process */ printf("*** ERROR: forking child process failed\n"); exit(1); } else if (pid == 0) { /* for the child process: */ if (execvp(*argv, argv) < 0) { /* exec command */ printf("*** ERROR: exec failed\n"); exit(1); } } else { /* for the parent: */ while (wait(&status) != pid) /* wait for completion */ ; } } void main(void) { char line[MAX]; /* the input line */ char *argv[64]; /* the command line argument */ while (1) { /* repeat until done .... */ printf("Shell -> "); /* display a prompt */ if (fgets(line, MAX, stdin) != 0){ line[strcspn(line, "\n")] = '\0'; printf("\n"); // Place your code here to check the command is "exit" // to terminate the shell. parse(line, argv); /* parse the line */ execute(argv); /* otherwise, execute cmd */ } } } b)Compile tryShell.c {cslinux1:~/week08Lab02} gcc tryShell.c -o tryShell c) Run tryShell {cslinux1:~/week08Lab02} ./tryShell Shell -> date
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help