SlideShare a Scribd company logo
#define LOGFILE "signal_log.txt"
// Signal handlers
void sigusr1_handler(int signo);
void sigusr2_handler(int signo);
void sighup_handler(int signo);
// SIGUSR1 handler
void sigusr1_handler(int signo)
{
dprintf(STDOUT_FILENO, "Signal %d (%s) received in function %s() at line %dn",
signo, strsignal(signo), __FUNCTION__, __LINE__);
fflush(stdout);
}
// SIGUSR2 handler
void sigusr2_handler(int signo)
{
dprintf(STDOUT_FILENO, "Signal %d (%s) received in function %s() at line %dn",
signo, strsignal(signo),__FUNCTION__, __LINE__);
fflush(stdout);
}
// SIGHUP handler
void sighup_handler(int signo)
{
dprintf(STDOUT_FILENO, "Signal %d (%s) received in function %s() at line %dn",
signo, strsignal(signo), __FUNCTION__, __LINE__);
fflush(stdout);
}
char *interpret(char *cmdline)
{
char **tokens;
char *cmd;
int i;
char *result;
char sysCommand;
tokens=history_tokenize(cmdline); //Split cmdline into individual words.
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]);
}
//Using struct CMDSTRUCT as an alternative lookup method. Pick either technique, not both
//Note that its possible to create multiple aliases for the same command using either method.
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;
}
signal(SIGIO, SIG_IGN);
signal(SIGUSR1, sigusr1_handler);
signal(SIGUSR2, sigusr2_handler);
signal(SIGHUP, sighup_handler);
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");
retur 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 #define LOGFILE signal_log.txt Signal handlers void sigusr1.pdf

C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
RashidFaridChishti
 
Unit5 (2)
Unit5 (2)Unit5 (2)
Unit5 (2)mrecedu
 
Os lab final
Os lab finalOs lab final
Os lab final
LakshmiSarvani6
 
C basics
C   basicsC   basics
First c program
First c programFirst c program
First c program
Komal Pardeshi
 
C for Java programmers (part 1)
C for Java programmers (part 1)C for Java programmers (part 1)
C for Java programmers (part 1)
Dmitry Zinoviev
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manualSami Said
 
Functions
FunctionsFunctions
Functions
Swarup Boro
 
Introduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoIntroduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John Lado
Mark John Lado, MIT
 
C Language Unit-5
C Language Unit-5C Language Unit-5
C Language Unit-5
kasaragadda srinivasrao
 
Cypherock Assessment (1).pdf
Cypherock Assessment (1).pdfCypherock Assessment (1).pdf
Cypherock Assessment (1).pdf
PARNIKA GUPTA
 
Lab report 201001067_201001104
Lab report 201001067_201001104Lab report 201001067_201001104
Lab report 201001067_201001104swena_gupta
 
Lab report 201001067_201001104
Lab report 201001067_201001104Lab report 201001067_201001104
Lab report 201001067_201001104swena_gupta
 
Lab report 201001067_201001104
Lab report 201001067_201001104Lab report 201001067_201001104
Lab report 201001067_201001104swena_gupta
 
망고100 보드로 놀아보자 15
망고100 보드로 놀아보자 15망고100 보드로 놀아보자 15
망고100 보드로 놀아보자 15종인 전
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
JavaTpoint.Com
 
IN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdfIN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdf
aratextails30
 
Write a task that will perform some of the functions performed by a s.docx
 Write a task that will perform some of the functions performed by a s.docx Write a task that will perform some of the functions performed by a s.docx
Write a task that will perform some of the functions performed by a s.docx
ajoy21
 

Similar to #define LOGFILE signal_log.txt Signal handlers void sigusr1.pdf (20)

C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
Unit5 (2)
Unit5 (2)Unit5 (2)
Unit5 (2)
 
Os lab final
Os lab finalOs lab final
Os lab final
 
Unit5 C
Unit5 C Unit5 C
Unit5 C
 
C basics
C   basicsC   basics
C basics
 
First c program
First c programFirst c program
First c program
 
C for Java programmers (part 1)
C for Java programmers (part 1)C for Java programmers (part 1)
C for Java programmers (part 1)
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manual
 
Functions
FunctionsFunctions
Functions
 
Introduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoIntroduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John Lado
 
C Language Unit-5
C Language Unit-5C Language Unit-5
C Language Unit-5
 
Cypherock Assessment (1).pdf
Cypherock Assessment (1).pdfCypherock Assessment (1).pdf
Cypherock Assessment (1).pdf
 
Lab report 201001067_201001104
Lab report 201001067_201001104Lab report 201001067_201001104
Lab report 201001067_201001104
 
Lab report 201001067_201001104
Lab report 201001067_201001104Lab report 201001067_201001104
Lab report 201001067_201001104
 
Lab report 201001067_201001104
Lab report 201001067_201001104Lab report 201001067_201001104
Lab report 201001067_201001104
 
망고100 보드로 놀아보자 15
망고100 보드로 놀아보자 15망고100 보드로 놀아보자 15
망고100 보드로 놀아보자 15
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
IN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdfIN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdf
 
Write a task that will perform some of the functions performed by a s.docx
 Write a task that will perform some of the functions performed by a s.docx Write a task that will perform some of the functions performed by a s.docx
Write a task that will perform some of the functions performed by a s.docx
 

More from alstradecentreerode

(Rational Class) - use the original files to create the new progra.pdf
(Rational Class) - use the original files to create the new progra.pdf(Rational Class) - use the original files to create the new progra.pdf
(Rational Class) - use the original files to create the new progra.pdf
alstradecentreerode
 
(Q001) Expand the Geotour10 folder in Google Earth by clicking the t.pdf
(Q001) Expand the Geotour10 folder in Google Earth by clicking the t.pdf(Q001) Expand the Geotour10 folder in Google Earth by clicking the t.pdf
(Q001) Expand the Geotour10 folder in Google Earth by clicking the t.pdf
alstradecentreerode
 
(if any) is your opportunity cost.pdf
(if any) is your opportunity cost.pdf(if any) is your opportunity cost.pdf
(if any) is your opportunity cost.pdf
alstradecentreerode
 
(Forecasting and forecast error metrics calculation) Suzy Homemaker .pdf
(Forecasting and forecast error metrics calculation) Suzy Homemaker .pdf(Forecasting and forecast error metrics calculation) Suzy Homemaker .pdf
(Forecasting and forecast error metrics calculation) Suzy Homemaker .pdf
alstradecentreerode
 
(Elementary Statistics) Computer=1100(102r+1).pdf
(Elementary Statistics) Computer=1100(102r+1).pdf(Elementary Statistics) Computer=1100(102r+1).pdf
(Elementary Statistics) Computer=1100(102r+1).pdf
alstradecentreerode
 
(Derecho empresarial) X le otorga a Y un patrimonio vitalicio. Pos.pdf
(Derecho empresarial) X le otorga a Y un patrimonio vitalicio. Pos.pdf(Derecho empresarial) X le otorga a Y un patrimonio vitalicio. Pos.pdf
(Derecho empresarial) X le otorga a Y un patrimonio vitalicio. Pos.pdf
alstradecentreerode
 
(d) Give a single line of R code that will produce a plot exactly li.pdf
(d) Give a single line of R code that will produce a plot exactly li.pdf(d) Give a single line of R code that will produce a plot exactly li.pdf
(d) Give a single line of R code that will produce a plot exactly li.pdf
alstradecentreerode
 
(5 points) There are seven boys and six girls. Coach wants to select.pdf
(5 points) There are seven boys and six girls. Coach wants to select.pdf(5 points) There are seven boys and six girls. Coach wants to select.pdf
(5 points) There are seven boys and six girls. Coach wants to select.pdf
alstradecentreerode
 
(1)1�(1+.10000000000000000000000(100))�2(126127) The single precision .pdf
(1)1�(1+.10000000000000000000000(100))�2(126127) The single precision .pdf(1)1�(1+.10000000000000000000000(100))�2(126127) The single precision .pdf
(1)1�(1+.10000000000000000000000(100))�2(126127) The single precision .pdf
alstradecentreerode
 
(1)CT13.1) Your parents are considering investing in Apple Inc. co.pdf
(1)CT13.1) Your parents are considering investing in Apple Inc. co.pdf(1)CT13.1) Your parents are considering investing in Apple Inc. co.pdf
(1)CT13.1) Your parents are considering investing in Apple Inc. co.pdf
alstradecentreerode
 
(10 points) Construct a BST by inserting the following keys into an .pdf
(10 points) Construct a BST by inserting the following keys into an .pdf(10 points) Construct a BST by inserting the following keys into an .pdf
(10 points) Construct a BST by inserting the following keys into an .pdf
alstradecentreerode
 
#2 Listed below are the numbers of triplets born in a country each y.pdf
#2 Listed below are the numbers of triplets born in a country each y.pdf#2 Listed below are the numbers of triplets born in a country each y.pdf
#2 Listed below are the numbers of triplets born in a country each y.pdf
alstradecentreerode
 
#52 In a large American university in 1969, the male and female pro.pdf
#52 In a large American university in 1969, the male and female pro.pdf#52 In a large American university in 1969, the male and female pro.pdf
#52 In a large American university in 1969, the male and female pro.pdf
alstradecentreerode
 
�Los Premios Darwin honran adecuadamente sus ideas sobre la selecci.pdf
 �Los Premios Darwin honran adecuadamente sus ideas sobre la selecci.pdf �Los Premios Darwin honran adecuadamente sus ideas sobre la selecci.pdf
�Los Premios Darwin honran adecuadamente sus ideas sobre la selecci.pdf
alstradecentreerode
 
�derine NTHikEaDs 10 itatic thresd-t thread void nolint all cosit os .pdf
 �derine NTHikEaDs 10 itatic thresd-t thread void nolint all cosit os .pdf �derine NTHikEaDs 10 itatic thresd-t thread void nolint all cosit os .pdf
�derine NTHikEaDs 10 itatic thresd-t thread void nolint all cosit os .pdf
alstradecentreerode
 
�Es el az�car bueno... malo... ninguno... ambos Dime por qu�. �Cu�.pdf
 �Es el az�car bueno... malo... ninguno... ambos Dime por qu�. �Cu�.pdf �Es el az�car bueno... malo... ninguno... ambos Dime por qu�. �Cu�.pdf
�Es el az�car bueno... malo... ninguno... ambos Dime por qu�. �Cu�.pdf
alstradecentreerode
 
�Cu�les de los siguientes son ejemplos de intervenciones de educa.pdf
 �Cu�les de los siguientes son ejemplos de intervenciones de educa.pdf �Cu�les de los siguientes son ejemplos de intervenciones de educa.pdf
�Cu�les de los siguientes son ejemplos de intervenciones de educa.pdf
alstradecentreerode
 
�Cu�l de los siguientes se considera un indicador principal de la e.pdf
 �Cu�l de los siguientes se considera un indicador principal de la e.pdf �Cu�l de los siguientes se considera un indicador principal de la e.pdf
�Cu�l de los siguientes se considera un indicador principal de la e.pdf
alstradecentreerode
 
�Cu�les son algunos ejemplos de comentarios sobre el terreno para l.pdf
 �Cu�les son algunos ejemplos de comentarios sobre el terreno para l.pdf �Cu�les son algunos ejemplos de comentarios sobre el terreno para l.pdf
�Cu�les son algunos ejemplos de comentarios sobre el terreno para l.pdf
alstradecentreerode
 

More from alstradecentreerode (20)

(Rational Class) - use the original files to create the new progra.pdf
(Rational Class) - use the original files to create the new progra.pdf(Rational Class) - use the original files to create the new progra.pdf
(Rational Class) - use the original files to create the new progra.pdf
 
(Q001) Expand the Geotour10 folder in Google Earth by clicking the t.pdf
(Q001) Expand the Geotour10 folder in Google Earth by clicking the t.pdf(Q001) Expand the Geotour10 folder in Google Earth by clicking the t.pdf
(Q001) Expand the Geotour10 folder in Google Earth by clicking the t.pdf
 
(if any) is your opportunity cost.pdf
(if any) is your opportunity cost.pdf(if any) is your opportunity cost.pdf
(if any) is your opportunity cost.pdf
 
(Forecasting and forecast error metrics calculation) Suzy Homemaker .pdf
(Forecasting and forecast error metrics calculation) Suzy Homemaker .pdf(Forecasting and forecast error metrics calculation) Suzy Homemaker .pdf
(Forecasting and forecast error metrics calculation) Suzy Homemaker .pdf
 
(Elementary Statistics) Computer=1100(102r+1).pdf
(Elementary Statistics) Computer=1100(102r+1).pdf(Elementary Statistics) Computer=1100(102r+1).pdf
(Elementary Statistics) Computer=1100(102r+1).pdf
 
(Derecho empresarial) X le otorga a Y un patrimonio vitalicio. Pos.pdf
(Derecho empresarial) X le otorga a Y un patrimonio vitalicio. Pos.pdf(Derecho empresarial) X le otorga a Y un patrimonio vitalicio. Pos.pdf
(Derecho empresarial) X le otorga a Y un patrimonio vitalicio. Pos.pdf
 
(d) Give a single line of R code that will produce a plot exactly li.pdf
(d) Give a single line of R code that will produce a plot exactly li.pdf(d) Give a single line of R code that will produce a plot exactly li.pdf
(d) Give a single line of R code that will produce a plot exactly li.pdf
 
(5 points) There are seven boys and six girls. Coach wants to select.pdf
(5 points) There are seven boys and six girls. Coach wants to select.pdf(5 points) There are seven boys and six girls. Coach wants to select.pdf
(5 points) There are seven boys and six girls. Coach wants to select.pdf
 
(2ab)5.pdf
(2ab)5.pdf(2ab)5.pdf
(2ab)5.pdf
 
(1)1�(1+.10000000000000000000000(100))�2(126127) The single precision .pdf
(1)1�(1+.10000000000000000000000(100))�2(126127) The single precision .pdf(1)1�(1+.10000000000000000000000(100))�2(126127) The single precision .pdf
(1)1�(1+.10000000000000000000000(100))�2(126127) The single precision .pdf
 
(1)CT13.1) Your parents are considering investing in Apple Inc. co.pdf
(1)CT13.1) Your parents are considering investing in Apple Inc. co.pdf(1)CT13.1) Your parents are considering investing in Apple Inc. co.pdf
(1)CT13.1) Your parents are considering investing in Apple Inc. co.pdf
 
(10 points) Construct a BST by inserting the following keys into an .pdf
(10 points) Construct a BST by inserting the following keys into an .pdf(10 points) Construct a BST by inserting the following keys into an .pdf
(10 points) Construct a BST by inserting the following keys into an .pdf
 
#2 Listed below are the numbers of triplets born in a country each y.pdf
#2 Listed below are the numbers of triplets born in a country each y.pdf#2 Listed below are the numbers of triplets born in a country each y.pdf
#2 Listed below are the numbers of triplets born in a country each y.pdf
 
#52 In a large American university in 1969, the male and female pro.pdf
#52 In a large American university in 1969, the male and female pro.pdf#52 In a large American university in 1969, the male and female pro.pdf
#52 In a large American university in 1969, the male and female pro.pdf
 
�Los Premios Darwin honran adecuadamente sus ideas sobre la selecci.pdf
 �Los Premios Darwin honran adecuadamente sus ideas sobre la selecci.pdf �Los Premios Darwin honran adecuadamente sus ideas sobre la selecci.pdf
�Los Premios Darwin honran adecuadamente sus ideas sobre la selecci.pdf
 
�derine NTHikEaDs 10 itatic thresd-t thread void nolint all cosit os .pdf
 �derine NTHikEaDs 10 itatic thresd-t thread void nolint all cosit os .pdf �derine NTHikEaDs 10 itatic thresd-t thread void nolint all cosit os .pdf
�derine NTHikEaDs 10 itatic thresd-t thread void nolint all cosit os .pdf
 
�Es el az�car bueno... malo... ninguno... ambos Dime por qu�. �Cu�.pdf
 �Es el az�car bueno... malo... ninguno... ambos Dime por qu�. �Cu�.pdf �Es el az�car bueno... malo... ninguno... ambos Dime por qu�. �Cu�.pdf
�Es el az�car bueno... malo... ninguno... ambos Dime por qu�. �Cu�.pdf
 
�Cu�les de los siguientes son ejemplos de intervenciones de educa.pdf
 �Cu�les de los siguientes son ejemplos de intervenciones de educa.pdf �Cu�les de los siguientes son ejemplos de intervenciones de educa.pdf
�Cu�les de los siguientes son ejemplos de intervenciones de educa.pdf
 
�Cu�l de los siguientes se considera un indicador principal de la e.pdf
 �Cu�l de los siguientes se considera un indicador principal de la e.pdf �Cu�l de los siguientes se considera un indicador principal de la e.pdf
�Cu�l de los siguientes se considera un indicador principal de la e.pdf
 
�Cu�les son algunos ejemplos de comentarios sobre el terreno para l.pdf
 �Cu�les son algunos ejemplos de comentarios sobre el terreno para l.pdf �Cu�les son algunos ejemplos de comentarios sobre el terreno para l.pdf
�Cu�les son algunos ejemplos de comentarios sobre el terreno para l.pdf
 

Recently uploaded

How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 

Recently uploaded (20)

How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 

#define LOGFILE signal_log.txt Signal handlers void sigusr1.pdf

  • 1. #define LOGFILE "signal_log.txt" // Signal handlers void sigusr1_handler(int signo); void sigusr2_handler(int signo); void sighup_handler(int signo); // SIGUSR1 handler void sigusr1_handler(int signo) { dprintf(STDOUT_FILENO, "Signal %d (%s) received in function %s() at line %dn", signo, strsignal(signo), __FUNCTION__, __LINE__); fflush(stdout); } // SIGUSR2 handler void sigusr2_handler(int signo) { dprintf(STDOUT_FILENO, "Signal %d (%s) received in function %s() at line %dn", signo, strsignal(signo),__FUNCTION__, __LINE__); fflush(stdout); } // SIGHUP handler void sighup_handler(int signo) { dprintf(STDOUT_FILENO, "Signal %d (%s) received in function %s() at line %dn", signo, strsignal(signo), __FUNCTION__, __LINE__); fflush(stdout); } char *interpret(char *cmdline) { char **tokens; char *cmd; int i; char *result; char sysCommand; tokens=history_tokenize(cmdline); //Split cmdline into individual words. if(!tokens) return "no response needed";
  • 2. 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]); } //Using struct CMDSTRUCT as an alternative lookup method. Pick either technique, not both //Note that its possible to create multiple aliases for the same command using either method. 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);
  • 3. } else { perror("getcwd() error"); return 1; } signal(SIGIO, SIG_IGN); signal(SIGUSR1, sigusr1_handler); signal(SIGUSR2, sigusr2_handler); signal(SIGHUP, sighup_handler); 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"); retur 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
  • 4. 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.