summaryrefslogtreecommitdiff
path: root/1088/CH24/EX24.14
diff options
context:
space:
mode:
Diffstat (limited to '1088/CH24/EX24.14')
-rwxr-xr-x1088/CH24/EX24.14/Example14.sce92
-rwxr-xr-x1088/CH24/EX24.14/Result14.txt96
2 files changed, 188 insertions, 0 deletions
diff --git a/1088/CH24/EX24.14/Example14.sce b/1088/CH24/EX24.14/Example14.sce
new file mode 100755
index 000000000..4550a5a8c
--- /dev/null
+++ b/1088/CH24/EX24.14/Example14.sce
@@ -0,0 +1,92 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 14 : Show the use of generating signals and how the system can be made to catch it \n")
+disp("****************************************************************")
+disp("Answer : ")
+disp("INSTRUCTIONS : ")
+halt(' ')
+disp("1.These programs are part of systems programming PURELY in Unix and the commands have NO EQUIVALENT IN SCILAB")
+halt(' ')
+disp("2.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and running the programme with gcc or cc compiler")
+halt(' ')
+disp("3.The outputs displayed here are just MOCK OUTPUTS which are DISPLAYED IN THE TEXTBOOK")
+halt(' ')
+disp("4.The inconvenience is regretted.")
+halt('.............Press [ENTER] to continue.....')
+halt("")
+clc
+printf("\tUNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)\n\n\n")
+i=0
+i=i+1;f(i)='/* Program: signal.c -- Waits for 5 seconds for user input and then generates SIGALRM that has a handler specified */'
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='#include <unistd.h>'
+i=i+1;f(i)='#include <signal.h>'
+i=i+1;f(i)='#define BUFSIZE 100'
+i=i+1;f(i)=''
+i=i+1;f(i)='void alrm_handler(int signo); /* Prototypes declarations for */'
+i=i+1;f(i)='void quit(char *message,int exit_status); /*signal handler and quit */'
+i=i+1;f(i)=''
+i=i+1;f(i)='char buf[BUFSIZE] = '+ascii(34)+'foo\0'+ascii(34)+'; /* Global variable */'
+i=i+1;f(i)='int main(void) {'
+i=i+1;f(i)=' int n;'
+i=i+1;f(i)=' if (signal(SIGALRM, alrm_handler) == SIG_ERR) /* signal returns SIG_ERR */'
+i=i+1;f(i)=' quit('+ascii(34)+'sigalrm'+ascii(34)+',1); /*on error*/'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' fprintf(stderr, '+ascii(34)+'Enter filename: '+ascii(34)+');'
+i=i+1;f(i)=' alarm(5); /* Sets alarm clock;will deliver */'
+i=i+1;f(i)=' n = read(STDIN_FILENO, buf, BUFSIZE); /* SIGALRM in 5 seconds */'
+i=i+1;f(i)=' if (n>1) /* Will come here if user inputs */'
+i=i+1;f(i)=' printf('+ascii(34)+'Filename: %s\n'+ascii(34)+',buf); /* string within 5 seconds */'
+i=i+1;f(i)=' exit(0);'
+i=i+1;f(i)='}'
+i=i+1;f(i)=''
+i=i+1;f(i)='void alrm_handler(int signo) { /* Invoked with process recieves SIGALRM */'
+i=i+1;f(i)=' signal(SIGALRM, alrm_handler); /* Resetting signal handler */'
+i=i+1;f(i)=' fprintf(stderr, '+ascii(34)+'\nSignal %d reeived, default filename: %s\n'+ascii(34)+', signo, buf);'
+i=i+1;f(i)=' exit(1);'
+i=i+1;f(i)='}'
+n=i
+
+
+printf("\n\n$ cat signal.c # to open the file emp.lst")
+halt(' ')
+u=mopen('signal.c','wt')
+for i=1:n
+ mfprintf(u,"%s\n",f(i))
+ printf("%s\n",f(i))
+end
+mclose(u)
+halt('')
+clc
+
+halt(' ')
+ printf("$ cc signal.c")
+ halt(' ')
+ printf("$ a.out ")
+ halt(' ')
+printf("Enter filename: ")
+sleep(1000);printf("s");sleep(300);printf("i");sleep(300);printf("g") ;sleep(300);printf("n") ;sleep(300);printf("a") ;sleep(300);printf("l") ;sleep(300);printf(".") ;sleep(300);printf("l") ;sleep(300);printf("o") ;sleep(300);printf("g") ;sleep(500) ;printf(" [-ENTER-]")
+printf("\nFilename: signal.log")
+halt('')
+printf("$ a.out")
+halt(' ')
+printf("Enter filename: # Do not enter anything")
+sleep(5000)
+printf("# Nothing entered in 5 seconds \n")
+printf("Signal 14 received, default filename: foo")
+halt(' ')
+printf("$ kill -l | grep 14 # What is signal 14")
+halt(' ')
+printf("13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGUSRI\n")
+halt(' ')
+printf("\n\n\n$ exit #To exit the current simulation terminal and return to Scilab console\n\n")
+halt("........# (hit [ENTER] for result)")
+//clc()
+
+printf("\n\n\t\t\tBACK TO SCILAB CONSOLE...\nLoading initial environment')
+sleep(1000)
+
+
diff --git a/1088/CH24/EX24.14/Result14.txt b/1088/CH24/EX24.14/Result14.txt
new file mode 100755
index 000000000..47981ab33
--- /dev/null
+++ b/1088/CH24/EX24.14/Result14.txt
@@ -0,0 +1,96 @@
+ ans =
+
+ 1.
+
+-->exec('Example14.sci')
+
+-->clear
+
+-->flag=1
+ flag =
+
+ 1.
+
+-->mode(-1)
+Current date is 23-Jun-2013
+
+Welcome to the Textbook Companionship Project 2013
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Book Title : UNIX CONCEPTS AND APPLICATIONS
+
+ Book Edition : 4
+
+ Book Author : Sumitabha Das
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Code Author : Pranav Bhat T
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Chapter Number : 24
+
+ Chapter Title : Systems programming II- Files
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+Example 14 : Show the use of generating signals and how the system can be made to catch it
+
+ ****************************************************************
+
+ Answer :
+
+ INSTRUCTIONS :
+
+ 1.These programs are part of systems programming PURELY in Unix and the commands have NO EQUIVALENT IN SCILAB
+
+ 2.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and
+ running the programme with gcc or cc compiler
+
+ 3.The outputs displayed here are just MOCK OUTPUTS which are DISPLAYED IN THE TEXTBOOK
+
+ 4.The inconvenience is regretted.
+.............Press [ENTER] to continue..... UNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)
+
+
+
+
+$ cat signal.c # to open the file emp.lst /* Program: signal.c -- Waits for 5 seconds for user input and then generates SIGALRM that has a handler specified */
+#include <stdio.h>
+#include <unistd.h>
+#include <signal.h>
+#define BUFSIZE 100
+
+void alrm_handler(int signo); /* Prototypes declarations for */
+void quit(char *message,int exit_status); /*signal handler and quit */
+
+char buf[BUFSIZE] = "foo\0"; /* Global variable */
+int main(void) {
+ int n;
+ if (signal(SIGALRM, alrm_handler) == SIG_ERR) /* signal returns SIG_ERR */
+ quit("sigalrm",1); /*on error*/
+
+ fprintf(stderr, "Enter filename: ");
+ alarm(5); /* Sets alarm clock;will deliver */
+ n = read(STDIN_FILENO, buf, BUFSIZE); /* SIGALRM in 5 seconds */
+ if (n>1) /* Will come here if user inputs */
+ printf("Filename: %s\n",buf); /* string within 5 seconds */
+ exit(0);
+}
+
+void alrm_handler(int signo) { /* Invoked with process recieves SIGALRM */
+ signal(SIGALRM, alrm_handler); /* Resetting signal handler */
+ fprintf(stderr, "\nSignal %d reeived, default filename: %s\n", signo, buf);
+ exit(1);
+}
+ $ cc signal.c $ a.out Enter filename: signal.log [-ENTER-]
+Filename: signal.log$ a.out Enter filename: # Nothing entered in 5 seconds
+Signal 14 received, default filename: foo $ kill -l | grep 14 # What is signal 14 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGUSRI
+
+
+
+$ exit #To exit the current simulation terminal and return to Scilab console
+
+........# (hit [ENTER] for result)
+
+ BACK TO SCILAB CONSOLE...
+Loading initial environment
+
+-->diary(0)