SlideShare a Scribd company logo
1 of 8
Download to read offline
int ch=chdir(tokensleft[0]);
/*if the change of directory was successful it will print successful otherwise it will print not
successful*/
if(ch<0)
perror("chdir change of directory not successfuln");
else
printf("chdir change of directory successfuln");
return "Command 'chdir' was receivedn";
}
char * fAccess(char *cmd,char *tokensleft[])
{
int exists =0;
for(int i=0;tokensleft[i]; i++) {
exists =0;
if(access(tokensleft[i],F_OK)==0){
exists = 1;
printf("file %s existsn",tokensleft[i]);
}else{
printf("file %s does not existsn",tokensleft[i]);
}
if (exists == 1){
if(access(tokensleft[i],R_OK)==0) {
printf("file %s is readablen",tokensleft[i]);
}else{printf("file %s is not readablen",tokensleft[i]);}
if(access(tokensleft[i],W_OK)==0) {
printf("file %s is writeablen",tokensleft[i]);
}else{
printf("file %s is not writeablen",tokensleft[i]);
}
if(access(tokensleft[i],X_OK)==0) {
printf("file %s is executeablen",tokensleft[i]);
}else{
printf("file %s is not executeablen",tokensleft[i]);
}
}
}
return "Command 'acsess' was receivedn";
}
char * fChmod(char *cmd,char *tokensleft[])
{
unsigned int octalPerm;
sscanf(tokensleft[0],"%o",&octalPerm);
for(int i=1;tokensleft[i]; i++) {
if(chmod(tokensleft[i],octalPerm)==0 ){
chmod(tokensleft[i],octalPerm);
}else{
printf("Error: %s n",strerror(errno));
}
}
return "Command 'chmod' was received";
}
char * fLn(char *cmd,char *tokensleft[])
{
int opt;
int force = 0;
int symbolic = 0;
int argc =0;
for (int i = 0; tokensleft[i]; i++) {
argc++;
}
while ((opt = getopt(argc, tokensleft, "sf")) != -1) {
switch (opt) {
case 's':
symbolic = 1;
break;
case 'f':
force = 1;
break;
default: /* '?' */
fprintf(stderr, "Usage: %s [-s] [-f] file1 file2n", tokensleft[0]);
}
}
if (argc - optind != 2) {
fprintf(stderr, "Usage: %s [-s] [-f] file1 file2n", tokensleft[0]);
}
const char *file1 = tokensleft[optind];
const char *file2 = tokensleft[optind+1];
if (force) {
remove(file2);
}
if (symbolic) {
link(file1, file2);
} else {
if (link(file1, file2) != 0) {
perror("Error creating hard link");
}
}
return "Command 'ln' was received";
}
char * fUnset(char *cmd, char *tokensleft[])
{
unsetenv(tokensleft[0]);
return "Command 'unset' was received";
}
char * fStat(char *cmd, char *tokensleft[])
{
struct stat info;
for(int i=0;tokensleft[i]; i++) {
stat(tokensleft[i], &info);
struct passwd *pw = getpwuid(info.st_uid);
struct group *gr = getgrgid(info.st_gid);
printf("File: %s",tokensleft[i]);
printf ("Owner: %s",pw->pw_name);
printf ("Group: %s",gr->gr_name);
}
return "Command 'stat' was received";
}
char * fPartial(char *cmd, char *tokensleft[])
{
struct passwd *pw;
setpwent();
char *result = malloc(1024);
result[0] = '0';
while ((pw = getpwent()) != NULL) {
if (strcasestr(pw->pw_name, tokensleft[0]) || strcasestr(pw->pw_gecos, tokensleft[0])) {
char *entry = malloc(strlen(pw->pw_name) + 2);
sprintf(entry, "%s,", pw->pw_name);
strcat(result, entry);
free(entry);
}
}
endpwent(); // close the password file
if (strlen(result) == 0) {
strcpy(result, "No matching users found.");
}
printf("Match Found: %s n",result);
return "Command 'partial' was received";
}
char * fshowTime(char *cmd, char *tokensleft[])
{
system(setenv("DISPLAY_FORMAT","%A, %B, %d, %y, %I:%M %p",1));
system(setenv("PARSE_FORMAT","%Y/%m/%d %H:%M:%S",1));
time_t rawtime;
struct tm *info;
char buffer[80];
time(&rawtime);
info = localtime(&rawtime);
if (!tokensleft[0]){
strftime(buffer,80,"%x - %I:%M%p", info);
printf("Current date & time : |%s|n", buffer );
}else{
}
return "Command 'showTime' was received";
}
char *commands[18]={"export","chdir","access","chmod",
"path","touch","ln","unset","stat","partial","showTime"} ;
char
*(*methods[18])()={fExport,fChdir,fAccess,fChmod,fPath,fTouch,fLn,fUnset,fStat,fPartial,fsho
wTime};
//Alternate declaration
struct CMDSTRUCT {
char *cmd;
char *(*method)();
}
cmdStruct[]={{"justin",fshowTime},{"paul",fPartial},{"sammy",fStat},{"fred",fExport},{"mary
",fChdir},{"clark",fAccess},{"sonia",fChmod},{"carlo",fPath},{"lalo",fTouch},{"samuel",fLn},
{"olga",fUnset},{NULL,NULL}} ;
char *interpret(char *cmdline)
{
char **tokens;
char *cmd;
int i;
char *result;
char sysCommand;
tokens=history_tokenize(cmdline);
if(!tokens) return "no response needed";
cmd=tokens[0];
//Detecting commands: table lookup: 2 techniques
//Using the parallel arrays to look up function calls
for(i=0;commands[i];i++)
{
if(strcasecmp(cmd,commands[i])==0) return (methods[i])(cmd,&tokens[1]);
}
for(i=0;cmdStruct[i].cmd;i++)
if(strcasecmp(cmd,cmdStruct[i].cmd)==0) return (cmdStruct[i].method)(cmd,&tokens[1]);
sysCommand=system(cmdline);
if (sysCommand==-1){
return"command status: fail";
}else if (sysCommand==0){
return"command status: sucsess";}
}
int main(int argc, char * argv[],char * envp[])
{
char cmd[100];
char *cmdLine;
char *expansion;
time_t now=time(NULL);
int nBytes; //size of msg rec'd
char cwd[PATH_MAX];
signal(SIGINT,ctrlCHandler);
read_history("shell.log");
add_history(ctime(&now));
fprintf(stdout,"Starting the shell at: %sn",ctime(&now));
while(true) {
if (getcwd(cwd, sizeof(cwd)) != NULL) {
printf("Current working dir: %sn", cwd);
} else {
perror("getcwd() error");
return 1;
}
cmdLine=readline("Enter a command: ");
if(!cmdLine) break;
history_expand(cmdLine,&expansion);
add_history(expansion);
if(strcasecmp(cmdLine,"bye")==0) break;
char *response=interpret(cmdLine);
fprintf(stdout,"%sn",response);
}
write_history("shell.log");
system("echo Your session history is; cat -n shell.log");
fprintf(stdout,"Server is now terminated n");
return 0;
} SIGHUP, Set up SIGIO as a signal to be ignored. (6 marks) a. The initial handler you should
write for each of them should be stub routines that output a message: "Signal # (SIGxxxx)
received in function _FUNCTION_. Use strsignal to output the name of the signal using dprintf
to send the output to a file. (The tail -f & command will be demonstrated to allow you to follow
text output to a file while a program is running. Take notes!) Display the name of the file, when
it was compiled and the line # of the output message. (2 marks) b. Test all of the above signal
handlers. (2 marks) i. Verify that all of your signal handlers work sending your command servers
each of the above signals from a 2nd terminal. ii. To set up a log file to record the output of
dprintf(fd, fmtstr, argsI) use one of more of the following before running your command server:
exec fd>/dev/tty #isplays the messages on the current terminal exec fd>/dev/pts/n #display on a
different terminal that you own exec fd>logfile #writes to a file tail -f logfile & #displays new
data as it is appended to logfile tail -f logfile >/dev/pts/n & #displays new data on an alternate
terminal Hand in a log file (as opposed to a screen shot) showing that you tested all of the signals
c. In a 3rd terminal attach strace to the pid of your command server. (2) i. Send each of the 4
signals to the pid of the command server. How does strace respond to each signal. Summarize
the result. ii. Send each of the 4 signals to the parent pid of the command server. Answer the
same question and hilite/describe any difference.

More Related Content

Similar to int ch=chdir(tokensleft[0]); if the change of director.pdf

So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfezonesolutions
 
IO redirection in C shellPlease implement input output redirect.pdf
IO redirection in C shellPlease implement input  output redirect.pdfIO redirection in C shellPlease implement input  output redirect.pdf
IO redirection in C shellPlease implement input output redirect.pdfforecastfashions
 
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Yandex
 
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdfAdrianEBJKingr
 
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbsSystem Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbsashukiller7
 
Railway reservation
Railway reservationRailway reservation
Railway reservationSwarup Boro
 
c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservationSwarup Kumar Boro
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 WorldFabien Potencier
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in cgkgaur1987
 
RAILWAY RESERWATION PROJECT PROGRAM
RAILWAY RESERWATION PROJECT PROGRAMRAILWAY RESERWATION PROJECT PROGRAM
RAILWAY RESERWATION PROJECT PROGRAMKrishna Raj
 
httplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxhttplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxadampcarr67227
 
Simple API for XML
Simple API for XMLSimple API for XML
Simple API for XMLguest2556de
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptxradhushri
 

Similar to int ch=chdir(tokensleft[0]); if the change of director.pdf (20)

So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdf
 
IO redirection in C shellPlease implement input output redirect.pdf
IO redirection in C shellPlease implement input  output redirect.pdfIO redirection in C shellPlease implement input  output redirect.pdf
IO redirection in C shellPlease implement input output redirect.pdf
 
Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++Степан Кольцов — Rust — лучше, чем C++
Степан Кольцов — Rust — лучше, чем C++
 
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
 
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbsSystem Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
 
Railway reservation
Railway reservationRailway reservation
Railway reservation
 
c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservation
 
PPS Notes Unit 5.pdf
PPS Notes Unit 5.pdfPPS Notes Unit 5.pdf
PPS Notes Unit 5.pdf
 
Python build your security tools.pdf
Python build your security tools.pdfPython build your security tools.pdf
Python build your security tools.pdf
 
Anti patterns
Anti patternsAnti patterns
Anti patterns
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
RAILWAY RESERWATION PROJECT PROGRAM
RAILWAY RESERWATION PROJECT PROGRAMRAILWAY RESERWATION PROJECT PROGRAM
RAILWAY RESERWATION PROJECT PROGRAM
 
httplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxhttplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docx
 
Railwaynew
RailwaynewRailwaynew
Railwaynew
 
Simple API for XML
Simple API for XMLSimple API for XML
Simple API for XML
 
Rust-lang
Rust-langRust-lang
Rust-lang
 
File management
File managementFile management
File management
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptx
 
C Programming Project
C Programming ProjectC Programming Project
C Programming Project
 

More from mdualudin007

(5 points 1. Which of the followhy statements munt be trie 2. What i.pdf
 (5 points 1. Which of the followhy statements munt be trie 2. What i.pdf (5 points 1. Which of the followhy statements munt be trie 2. What i.pdf
(5 points 1. Which of the followhy statements munt be trie 2. What i.pdfmdualudin007
 
(4) With regard to virulence factors, what do the letters O,H and K.pdf
 (4) With regard to virulence factors, what do the letters O,H and K.pdf (4) With regard to virulence factors, what do the letters O,H and K.pdf
(4) With regard to virulence factors, what do the letters O,H and K.pdfmdualudin007
 
(4 points) Match the following data with the correct level of measure.pdf
 (4 points) Match the following data with the correct level of measure.pdf (4 points) Match the following data with the correct level of measure.pdf
(4 points) Match the following data with the correct level of measure.pdfmdualudin007
 
(3) If events occur accordiy to a poidson porles with hate =10minnt..pdf
 (3) If events occur accordiy to a poidson porles with hate =10minnt..pdf (3) If events occur accordiy to a poidson porles with hate =10minnt..pdf
(3) If events occur accordiy to a poidson porles with hate =10minnt..pdfmdualudin007
 
(4 marks) Suppose the production function of the fishing industry is .pdf
 (4 marks) Suppose the production function of the fishing industry is .pdf (4 marks) Suppose the production function of the fishing industry is .pdf
(4 marks) Suppose the production function of the fishing industry is .pdfmdualudin007
 
(3 points) Employee is a derived class of Person, and Worker is a der.pdf
 (3 points) Employee is a derived class of Person, and Worker is a der.pdf (3 points) Employee is a derived class of Person, and Worker is a der.pdf
(3 points) Employee is a derived class of Person, and Worker is a der.pdfmdualudin007
 
(1 point) Suppose that the demand of a certain item is x=10+p21. Eval.pdf
 (1 point) Suppose that the demand of a certain item is x=10+p21. Eval.pdf (1 point) Suppose that the demand of a certain item is x=10+p21. Eval.pdf
(1 point) Suppose that the demand of a certain item is x=10+p21. Eval.pdfmdualudin007
 
() Source Monthly Bulletins of the Central Bank of Venezuela. All l.pdf
 () Source Monthly Bulletins of the Central Bank of Venezuela. All l.pdf () Source Monthly Bulletins of the Central Bank of Venezuela. All l.pdf
() Source Monthly Bulletins of the Central Bank of Venezuela. All l.pdfmdualudin007
 
(1 Point) Please match the following variable properties with their d.pdf
 (1 Point) Please match the following variable properties with their d.pdf (1 Point) Please match the following variable properties with their d.pdf
(1 Point) Please match the following variable properties with their d.pdfmdualudin007
 
(1 point) If samples of size 37 are taken from a population with mean.pdf
 (1 point) If samples of size 37 are taken from a population with mean.pdf (1 point) If samples of size 37 are taken from a population with mean.pdf
(1 point) If samples of size 37 are taken from a population with mean.pdfmdualudin007
 
Bag breaks open; included as delay in the allowance factor Conveyo.pdf
  Bag breaks open; included as delay in the allowance factor  Conveyo.pdf  Bag breaks open; included as delay in the allowance factor  Conveyo.pdf
Bag breaks open; included as delay in the allowance factor Conveyo.pdfmdualudin007
 
Prove the following E(MSR)=2+12(Xix)2.pdf
  Prove the following E(MSR)=2+12(Xix)2.pdf  Prove the following E(MSR)=2+12(Xix)2.pdf
Prove the following E(MSR)=2+12(Xix)2.pdfmdualudin007
 
Computer Architecture HOW do I design a computer = Instruction .pdf
  Computer Architecture HOW do I design a computer  = Instruction .pdf  Computer Architecture HOW do I design a computer  = Instruction .pdf
Computer Architecture HOW do I design a computer = Instruction .pdfmdualudin007
 
( Ch2 ISA)3. Assume that the top of the stack in a progra.pdf
 ( Ch2 ISA)3. Assume that the top of the stack in a progra.pdf ( Ch2 ISA)3. Assume that the top of the stack in a progra.pdf
( Ch2 ISA)3. Assume that the top of the stack in a progra.pdfmdualudin007
 
The goal of this assignment is to get familiar with pipelining in C.pdf
  The goal of this assignment is to get familiar with pipelining in C.pdf  The goal of this assignment is to get familiar with pipelining in C.pdf
The goal of this assignment is to get familiar with pipelining in C.pdfmdualudin007
 
( 20 points) Benzene is a common groundwater contaminant. Based on a .pdf
 ( 20 points) Benzene is a common groundwater contaminant. Based on a .pdf ( 20 points) Benzene is a common groundwater contaminant. Based on a .pdf
( 20 points) Benzene is a common groundwater contaminant. Based on a .pdfmdualudin007
 
(2) Solve the following recurrence relation by using Recursion Trees .pdf
 (2) Solve the following recurrence relation by using Recursion Trees .pdf (2) Solve the following recurrence relation by using Recursion Trees .pdf
(2) Solve the following recurrence relation by using Recursion Trees .pdfmdualudin007
 
(20 pts) Let X and Y be two statistically independent random variable.pdf
 (20 pts) Let X and Y be two statistically independent random variable.pdf (20 pts) Let X and Y be two statistically independent random variable.pdf
(20 pts) Let X and Y be two statistically independent random variable.pdfmdualudin007
 
(2 pts.) Consider the following ordered list of data, x and a key.pdf
 (2 pts.) Consider the following ordered list of data,  x  and a key.pdf (2 pts.) Consider the following ordered list of data,  x  and a key.pdf
(2 pts.) Consider the following ordered list of data, x and a key.pdfmdualudin007
 
(2 points) (Problem 4.96) Suppose that a random variable Y has a prob.pdf
 (2 points) (Problem 4.96) Suppose that a random variable Y has a prob.pdf (2 points) (Problem 4.96) Suppose that a random variable Y has a prob.pdf
(2 points) (Problem 4.96) Suppose that a random variable Y has a prob.pdfmdualudin007
 

More from mdualudin007 (20)

(5 points 1. Which of the followhy statements munt be trie 2. What i.pdf
 (5 points 1. Which of the followhy statements munt be trie 2. What i.pdf (5 points 1. Which of the followhy statements munt be trie 2. What i.pdf
(5 points 1. Which of the followhy statements munt be trie 2. What i.pdf
 
(4) With regard to virulence factors, what do the letters O,H and K.pdf
 (4) With regard to virulence factors, what do the letters O,H and K.pdf (4) With regard to virulence factors, what do the letters O,H and K.pdf
(4) With regard to virulence factors, what do the letters O,H and K.pdf
 
(4 points) Match the following data with the correct level of measure.pdf
 (4 points) Match the following data with the correct level of measure.pdf (4 points) Match the following data with the correct level of measure.pdf
(4 points) Match the following data with the correct level of measure.pdf
 
(3) If events occur accordiy to a poidson porles with hate =10minnt..pdf
 (3) If events occur accordiy to a poidson porles with hate =10minnt..pdf (3) If events occur accordiy to a poidson porles with hate =10minnt..pdf
(3) If events occur accordiy to a poidson porles with hate =10minnt..pdf
 
(4 marks) Suppose the production function of the fishing industry is .pdf
 (4 marks) Suppose the production function of the fishing industry is .pdf (4 marks) Suppose the production function of the fishing industry is .pdf
(4 marks) Suppose the production function of the fishing industry is .pdf
 
(3 points) Employee is a derived class of Person, and Worker is a der.pdf
 (3 points) Employee is a derived class of Person, and Worker is a der.pdf (3 points) Employee is a derived class of Person, and Worker is a der.pdf
(3 points) Employee is a derived class of Person, and Worker is a der.pdf
 
(1 point) Suppose that the demand of a certain item is x=10+p21. Eval.pdf
 (1 point) Suppose that the demand of a certain item is x=10+p21. Eval.pdf (1 point) Suppose that the demand of a certain item is x=10+p21. Eval.pdf
(1 point) Suppose that the demand of a certain item is x=10+p21. Eval.pdf
 
() Source Monthly Bulletins of the Central Bank of Venezuela. All l.pdf
 () Source Monthly Bulletins of the Central Bank of Venezuela. All l.pdf () Source Monthly Bulletins of the Central Bank of Venezuela. All l.pdf
() Source Monthly Bulletins of the Central Bank of Venezuela. All l.pdf
 
(1 Point) Please match the following variable properties with their d.pdf
 (1 Point) Please match the following variable properties with their d.pdf (1 Point) Please match the following variable properties with their d.pdf
(1 Point) Please match the following variable properties with their d.pdf
 
(1 point) If samples of size 37 are taken from a population with mean.pdf
 (1 point) If samples of size 37 are taken from a population with mean.pdf (1 point) If samples of size 37 are taken from a population with mean.pdf
(1 point) If samples of size 37 are taken from a population with mean.pdf
 
Bag breaks open; included as delay in the allowance factor Conveyo.pdf
  Bag breaks open; included as delay in the allowance factor  Conveyo.pdf  Bag breaks open; included as delay in the allowance factor  Conveyo.pdf
Bag breaks open; included as delay in the allowance factor Conveyo.pdf
 
Prove the following E(MSR)=2+12(Xix)2.pdf
  Prove the following E(MSR)=2+12(Xix)2.pdf  Prove the following E(MSR)=2+12(Xix)2.pdf
Prove the following E(MSR)=2+12(Xix)2.pdf
 
Computer Architecture HOW do I design a computer = Instruction .pdf
  Computer Architecture HOW do I design a computer  = Instruction .pdf  Computer Architecture HOW do I design a computer  = Instruction .pdf
Computer Architecture HOW do I design a computer = Instruction .pdf
 
( Ch2 ISA)3. Assume that the top of the stack in a progra.pdf
 ( Ch2 ISA)3. Assume that the top of the stack in a progra.pdf ( Ch2 ISA)3. Assume that the top of the stack in a progra.pdf
( Ch2 ISA)3. Assume that the top of the stack in a progra.pdf
 
The goal of this assignment is to get familiar with pipelining in C.pdf
  The goal of this assignment is to get familiar with pipelining in C.pdf  The goal of this assignment is to get familiar with pipelining in C.pdf
The goal of this assignment is to get familiar with pipelining in C.pdf
 
( 20 points) Benzene is a common groundwater contaminant. Based on a .pdf
 ( 20 points) Benzene is a common groundwater contaminant. Based on a .pdf ( 20 points) Benzene is a common groundwater contaminant. Based on a .pdf
( 20 points) Benzene is a common groundwater contaminant. Based on a .pdf
 
(2) Solve the following recurrence relation by using Recursion Trees .pdf
 (2) Solve the following recurrence relation by using Recursion Trees .pdf (2) Solve the following recurrence relation by using Recursion Trees .pdf
(2) Solve the following recurrence relation by using Recursion Trees .pdf
 
(20 pts) Let X and Y be two statistically independent random variable.pdf
 (20 pts) Let X and Y be two statistically independent random variable.pdf (20 pts) Let X and Y be two statistically independent random variable.pdf
(20 pts) Let X and Y be two statistically independent random variable.pdf
 
(2 pts.) Consider the following ordered list of data, x and a key.pdf
 (2 pts.) Consider the following ordered list of data,  x  and a key.pdf (2 pts.) Consider the following ordered list of data,  x  and a key.pdf
(2 pts.) Consider the following ordered list of data, x and a key.pdf
 
(2 points) (Problem 4.96) Suppose that a random variable Y has a prob.pdf
 (2 points) (Problem 4.96) Suppose that a random variable Y has a prob.pdf (2 points) (Problem 4.96) Suppose that a random variable Y has a prob.pdf
(2 points) (Problem 4.96) Suppose that a random variable Y has a prob.pdf
 

Recently uploaded

Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading RoomImplanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading RoomSean M. Fox
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Denish Jangid
 
Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024CapitolTechU
 
How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17Celine George
 
How to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryHow to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryCeline George
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/siemaillard
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhleson0603
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Mohamed Rizk Khodair
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...Nguyen Thanh Tu Collection
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxheathfieldcps1
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...Krashi Coaching
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 

Recently uploaded (20)

Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading RoomImplanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
IPL Online Quiz by Pragya; Question Set.
IPL Online Quiz by Pragya; Question Set.IPL Online Quiz by Pragya; Question Set.
IPL Online Quiz by Pragya; Question Set.
 
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
Basic Civil Engineering notes on Transportation Engineering, Modes of Transpo...
 
Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024Capitol Tech Univ Doctoral Presentation -May 2024
Capitol Tech Univ Doctoral Presentation -May 2024
 
How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17
 
How to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryHow to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 Inventory
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
“O BEIJO” EM ARTE .
“O BEIJO” EM ARTE                       .“O BEIJO” EM ARTE                       .
“O BEIJO” EM ARTE .
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
 
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
MSc Ag Genetics & Plant Breeding: Insights from Previous Year JNKVV Entrance ...
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 

int ch=chdir(tokensleft[0]); if the change of director.pdf

  • 1. int ch=chdir(tokensleft[0]); /*if the change of directory was successful it will print successful otherwise it will print not successful*/ if(ch<0) perror("chdir change of directory not successfuln"); else printf("chdir change of directory successfuln"); return "Command 'chdir' was receivedn"; } char * fAccess(char *cmd,char *tokensleft[]) { int exists =0; for(int i=0;tokensleft[i]; i++) { exists =0; if(access(tokensleft[i],F_OK)==0){ exists = 1; printf("file %s existsn",tokensleft[i]); }else{ printf("file %s does not existsn",tokensleft[i]); } if (exists == 1){ if(access(tokensleft[i],R_OK)==0) { printf("file %s is readablen",tokensleft[i]); }else{printf("file %s is not readablen",tokensleft[i]);} if(access(tokensleft[i],W_OK)==0) { printf("file %s is writeablen",tokensleft[i]); }else{ printf("file %s is not writeablen",tokensleft[i]);
  • 2. } if(access(tokensleft[i],X_OK)==0) { printf("file %s is executeablen",tokensleft[i]); }else{ printf("file %s is not executeablen",tokensleft[i]); } } } return "Command 'acsess' was receivedn"; } char * fChmod(char *cmd,char *tokensleft[]) { unsigned int octalPerm; sscanf(tokensleft[0],"%o",&octalPerm); for(int i=1;tokensleft[i]; i++) { if(chmod(tokensleft[i],octalPerm)==0 ){ chmod(tokensleft[i],octalPerm); }else{ printf("Error: %s n",strerror(errno)); } } return "Command 'chmod' was received"; } char * fLn(char *cmd,char *tokensleft[]) { int opt; int force = 0; int symbolic = 0; int argc =0;
  • 3. for (int i = 0; tokensleft[i]; i++) { argc++; } while ((opt = getopt(argc, tokensleft, "sf")) != -1) { switch (opt) { case 's': symbolic = 1; break; case 'f': force = 1; break; default: /* '?' */ fprintf(stderr, "Usage: %s [-s] [-f] file1 file2n", tokensleft[0]); } } if (argc - optind != 2) { fprintf(stderr, "Usage: %s [-s] [-f] file1 file2n", tokensleft[0]); } const char *file1 = tokensleft[optind]; const char *file2 = tokensleft[optind+1]; if (force) { remove(file2); } if (symbolic) { link(file1, file2); } else { if (link(file1, file2) != 0) { perror("Error creating hard link"); }
  • 4. } return "Command 'ln' was received"; } char * fUnset(char *cmd, char *tokensleft[]) { unsetenv(tokensleft[0]); return "Command 'unset' was received"; } char * fStat(char *cmd, char *tokensleft[]) { struct stat info; for(int i=0;tokensleft[i]; i++) { stat(tokensleft[i], &info); struct passwd *pw = getpwuid(info.st_uid); struct group *gr = getgrgid(info.st_gid); printf("File: %s",tokensleft[i]); printf ("Owner: %s",pw->pw_name); printf ("Group: %s",gr->gr_name); } return "Command 'stat' was received"; } char * fPartial(char *cmd, char *tokensleft[]) { struct passwd *pw; setpwent(); char *result = malloc(1024); result[0] = '0'; while ((pw = getpwent()) != NULL) {
  • 5. if (strcasestr(pw->pw_name, tokensleft[0]) || strcasestr(pw->pw_gecos, tokensleft[0])) { char *entry = malloc(strlen(pw->pw_name) + 2); sprintf(entry, "%s,", pw->pw_name); strcat(result, entry); free(entry); } } endpwent(); // close the password file if (strlen(result) == 0) { strcpy(result, "No matching users found."); } printf("Match Found: %s n",result); return "Command 'partial' was received"; } char * fshowTime(char *cmd, char *tokensleft[]) { system(setenv("DISPLAY_FORMAT","%A, %B, %d, %y, %I:%M %p",1)); system(setenv("PARSE_FORMAT","%Y/%m/%d %H:%M:%S",1)); time_t rawtime; struct tm *info; char buffer[80]; time(&rawtime); info = localtime(&rawtime); if (!tokensleft[0]){ strftime(buffer,80,"%x - %I:%M%p", info); printf("Current date & time : |%s|n", buffer ); }else{ } return "Command 'showTime' was received"; }
  • 6. char *commands[18]={"export","chdir","access","chmod", "path","touch","ln","unset","stat","partial","showTime"} ; char *(*methods[18])()={fExport,fChdir,fAccess,fChmod,fPath,fTouch,fLn,fUnset,fStat,fPartial,fsho wTime}; //Alternate declaration struct CMDSTRUCT { char *cmd; char *(*method)(); } cmdStruct[]={{"justin",fshowTime},{"paul",fPartial},{"sammy",fStat},{"fred",fExport},{"mary ",fChdir},{"clark",fAccess},{"sonia",fChmod},{"carlo",fPath},{"lalo",fTouch},{"samuel",fLn}, {"olga",fUnset},{NULL,NULL}} ; char *interpret(char *cmdline) { char **tokens; char *cmd; int i; char *result; char sysCommand; tokens=history_tokenize(cmdline); if(!tokens) return "no response needed"; cmd=tokens[0]; //Detecting commands: table lookup: 2 techniques //Using the parallel arrays to look up function calls for(i=0;commands[i];i++) { if(strcasecmp(cmd,commands[i])==0) return (methods[i])(cmd,&tokens[1]); } for(i=0;cmdStruct[i].cmd;i++) if(strcasecmp(cmd,cmdStruct[i].cmd)==0) return (cmdStruct[i].method)(cmd,&tokens[1]); sysCommand=system(cmdline); if (sysCommand==-1){
  • 7. return"command status: fail"; }else if (sysCommand==0){ return"command status: sucsess";} } int main(int argc, char * argv[],char * envp[]) { char cmd[100]; char *cmdLine; char *expansion; time_t now=time(NULL); int nBytes; //size of msg rec'd char cwd[PATH_MAX]; signal(SIGINT,ctrlCHandler); read_history("shell.log"); add_history(ctime(&now)); fprintf(stdout,"Starting the shell at: %sn",ctime(&now)); while(true) { if (getcwd(cwd, sizeof(cwd)) != NULL) { printf("Current working dir: %sn", cwd); } else { perror("getcwd() error"); return 1; } cmdLine=readline("Enter a command: "); if(!cmdLine) break; history_expand(cmdLine,&expansion); add_history(expansion); if(strcasecmp(cmdLine,"bye")==0) break; char *response=interpret(cmdLine); fprintf(stdout,"%sn",response); } write_history("shell.log");
  • 8. system("echo Your session history is; cat -n shell.log"); fprintf(stdout,"Server is now terminated n"); return 0; } SIGHUP, Set up SIGIO as a signal to be ignored. (6 marks) a. The initial handler you should write for each of them should be stub routines that output a message: "Signal # (SIGxxxx) received in function _FUNCTION_. Use strsignal to output the name of the signal using dprintf to send the output to a file. (The tail -f & command will be demonstrated to allow you to follow text output to a file while a program is running. Take notes!) Display the name of the file, when it was compiled and the line # of the output message. (2 marks) b. Test all of the above signal handlers. (2 marks) i. Verify that all of your signal handlers work sending your command servers each of the above signals from a 2nd terminal. ii. To set up a log file to record the output of dprintf(fd, fmtstr, argsI) use one of more of the following before running your command server: exec fd>/dev/tty #isplays the messages on the current terminal exec fd>/dev/pts/n #display on a different terminal that you own exec fd>logfile #writes to a file tail -f logfile & #displays new data as it is appended to logfile tail -f logfile >/dev/pts/n & #displays new data on an alternate terminal Hand in a log file (as opposed to a screen shot) showing that you tested all of the signals c. In a 3rd terminal attach strace to the pid of your command server. (2) i. Send each of the 4 signals to the pid of the command server. How does strace respond to each signal. Summarize the result. ii. Send each of the 4 signals to the parent pid of the command server. Answer the same question and hilite/describe any difference.