summaryrefslogtreecommitdiff
path: root/1088/CH24
diff options
context:
space:
mode:
authorpriyanka2015-06-24 15:03:17 +0530
committerpriyanka2015-06-24 15:03:17 +0530
commitb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch)
treeab291cffc65280e58ac82470ba63fbcca7805165 /1088/CH24
downloadScilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip
initial commit / add all books
Diffstat (limited to '1088/CH24')
-rwxr-xr-x1088/CH24/EX24.1/Example1.sce59
-rwxr-xr-x1088/CH24/EX24.1/Result1.txt75
-rwxr-xr-x1088/CH24/EX24.10/Example10.sce73
-rwxr-xr-x1088/CH24/EX24.10/Result10.txt84
-rwxr-xr-x1088/CH24/EX24.11/Example11.sce87
-rwxr-xr-x1088/CH24/EX24.11/Result11.txt93
-rwxr-xr-x1088/CH24/EX24.12/Example12.sce75
-rwxr-xr-x1088/CH24/EX24.12/Result12.txt87
-rwxr-xr-x1088/CH24/EX24.13/Example13.sce77
-rwxr-xr-x1088/CH24/EX24.13/Result13.txt93
-rwxr-xr-x1088/CH24/EX24.14/Example14.sce92
-rwxr-xr-x1088/CH24/EX24.14/Result14.txt96
-rwxr-xr-x1088/CH24/EX24.15/Example15.sce93
-rwxr-xr-x1088/CH24/EX24.15/Result15.txt98
-rwxr-xr-x1088/CH24/EX24.16/Example16.sce109
-rwxr-xr-x1088/CH24/EX24.16/Result16.txt110
-rwxr-xr-x1088/CH24/EX24.2/Example2.sce74
-rwxr-xr-x1088/CH24/EX24.2/Result2.txt92
-rwxr-xr-x1088/CH24/EX24.3/Example3.sce101
-rwxr-xr-x1088/CH24/EX24.3/Result3.txt115
-rwxr-xr-x1088/CH24/EX24.4/Example4.sce82
-rwxr-xr-x1088/CH24/EX24.4/Result4.txt96
-rwxr-xr-x1088/CH24/EX24.5/Example5.sce70
-rwxr-xr-x1088/CH24/EX24.5/Result5.txt77
-rwxr-xr-x1088/CH24/EX24.6/Example6.sce58
-rwxr-xr-x1088/CH24/EX24.6/Result6.txt70
-rwxr-xr-x1088/CH24/EX24.7/Example7.sce61
-rwxr-xr-x1088/CH24/EX24.7/Result7.txt72
-rwxr-xr-x1088/CH24/EX24.8/Example8.sce72
-rwxr-xr-x1088/CH24/EX24.8/Result8.txt84
-rwxr-xr-x1088/CH24/EX24.9/Example9.sce118
-rwxr-xr-x1088/CH24/EX24.9/Result9.txt109
32 files changed, 2752 insertions, 0 deletions
diff --git a/1088/CH24/EX24.1/Example1.sce b/1088/CH24/EX24.1/Example1.sce
new file mode 100755
index 000000000..045f764f7
--- /dev/null
+++ b/1088/CH24/EX24.1/Example1.sce
@@ -0,0 +1,59 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 1 : Show the method of showing all the type of process IDs \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: process.c -- Lists process and user credentials The PID, PPID, real and effective UIDs and GIDs */'
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='int main(void) {'
+i=i+1;f(i)=' printf('+ascii(34)+'PID : %4d,PPDI : %4d\n'+ascii(34)+',getpid(),getppid());'
+i=i+1;f(i)=' printf('+ascii(34)+'UID : %4d, GID : %4d\n'+ascii(34)+',getuid(),getgid());'
+i=i+1;f(i)=' printf('+ascii(34)+'EUID : %4d,EGID : %4d\n'+ascii(34)+',geteuid(),getegid());'
+i=i+1;f(i)=' exit(0);'
+i=i+1;f(i)='}'
+n=i
+
+printf("\n\n$ cat process.c # to open the file emp.lst")
+halt(' ')
+u=mopen('process.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 process.c")
+ halt(' ')
+ printf("$ a.out")
+ halt(' ')
+ printf("PID : 1035, PPID: 1028\nUID : 102, GID: 10\nEUID: 102, EGID: 10\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.1/Result1.txt b/1088/CH24/EX24.1/Result1.txt
new file mode 100755
index 000000000..ddc5f891f
--- /dev/null
+++ b/1088/CH24/EX24.1/Result1.txt
@@ -0,0 +1,75 @@
+ ans =
+
+ 1.
+
+-->exec('Example1.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- Process Control
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+Example 1 : Show the method of showing all the type of process IDs
+
+ ****************************************************************
+
+ 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 process.c # to open the file emp.lst /* Program: process.c -- Lists process and user credentials The PID, PPID, real and effective UIDs and GIDs */
+#include <stdio.h>
+int main(void) {
+ printf("PID : %4d,PPDI : %4d\n",getpid(),getppid());
+ printf("UID : %4d, GID : %4d\n",getuid(),getgid());
+ printf("EUID : %4d,EGID : %4d\n",geteuid(),getegid());
+ exit(0);
+}
+ $ cc process.c $ a.out PID : 1035, PPID: 1028
+UID : 102, GID: 10
+EUID: 102, EGID: 10
+
+
+
+$ 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)
diff --git a/1088/CH24/EX24.10/Example10.sce b/1088/CH24/EX24.10/Example10.sce
new file mode 100755
index 000000000..c7481229c
--- /dev/null
+++ b/1088/CH24/EX24.10/Example10.sce
@@ -0,0 +1,73 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 10 : Show the effect of using dup command to achieve both input and output redirection\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: dup.c -- Uses dup to achieve both input and output redirection Closes standard streams first before using dup */'
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='#include <unistd.h>'
+i=i+1;f(i)='#include <sys/stat.h>'
+i=i+1;f(i)='#include <fcntl.h>'
+i=i+1;f(i)='#define MODE600 (S_IRUSR | S_IWUSR)'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(int argc,char **argv) {'
+i=i+1;f(i)=' int fd1,int fd2;'
+i=i+1;f(i)=' fd1 = open(argv[1],O_RDONLY);'
+i=i+1;f(i)=' fd2 = open(argv[2], O_WRONLY | O_CREAT |O_TRUNC, MODE600);'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' close(STDIN_FILENO); /*This should return descriptor 0 */'
+i=i+1;f(i)=' dup(fd1);'
+i=i+1;f(i)=' close(STDOUT_FILENO); /*This should return descriptor 1 */'
+i=i+1;f(i)=' dup(fd2);'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' execvp(argv[3], &argv[3]); /* Execute any filter */'
+i=i+1;f(i)=' printf('+ascii(34)+'Failed to exec filter'+ascii(34)+');'
+i=i+1;f(i)='}'
+n=i
+
+
+printf("\n\n$ cat dup.c # to open the file emp.lst")
+halt(' ')
+u=mopen('dup.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 shell.c")
+ halt(' ')
+ printf("$ a.out /etc/passwd passwd.cnt wc -1")
+ halt(' ')
+ printf("cat passwd.cnt")
+halt(' ')
+printf(" 37 /etc/passwd")
+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.10/Result10.txt b/1088/CH24/EX24.10/Result10.txt
new file mode 100755
index 000000000..9448d5ccc
--- /dev/null
+++ b/1088/CH24/EX24.10/Result10.txt
@@ -0,0 +1,84 @@
+ ans =
+
+ 1.
+
+-->exec('Example10.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 10 : Show the effect of using dup command to achieve both input and output redirection
+
+ ****************************************************************
+
+ 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 dup.c # to open the file emp.lst /* Program: dup.c -- Uses dup to achieve both input and output redirection Closes standard streams first before using dup */
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#define MODE600 (S_IRUSR | S_IWUSR)
+
+int main(int argc,char **argv) {
+ int fd1,int fd2;
+ fd1 = open(argv[1],O_RDONLY);
+ fd2 = open(argv[2], O_WRONLY | O_CREAT |O_TRUNC, MODE600);
+
+ close(STDIN_FILENO); /*This should return descriptor 0 */
+ dup(fd1);
+ close(STDOUT_FILENO); /*This should return descriptor 1 */
+ dup(fd2);
+
+ execvp(argv[3], &argv[3]); /* Execute any filter */
+ printf("Failed to exec filter");
+}
+ $ cc shell.c $ a.out /etc/passwd passwd.cnt wc -1 cat passwd.cnt 37 /etc/passwd
+
+
+$ 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)
diff --git a/1088/CH24/EX24.11/Example11.sce b/1088/CH24/EX24.11/Example11.sce
new file mode 100755
index 000000000..108bac1ca
--- /dev/null
+++ b/1088/CH24/EX24.11/Example11.sce
@@ -0,0 +1,87 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 11 : Show the effect of opening files int the parent and the child to reassign descriptors \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: dup2.c -- Opens files in the parent and uses dup2 in the child to reassign the descriptors */'
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='#include <unistd.h>'
+i=i+1;f(i)='#include <sys/stat.h>'
+i=i+1;f(i)='#include <fcntl.h>'
+i=i+1;f(i)='#include <wait.h>'
+i=i+1;f(i)=''
+i=i+1;f(i)='#define OPENFLAGS (O_WRONLY | O_CREAT | O_TRUNC)'
+i=i+1;f(i)='#define MODE600 (S_IRUSR | S_IWUSR)'
+i=i+1;f(i)=''
+i=i+1;f(i)='void quit(char *message, int exit_status) ;'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(int argc,char **argv) {'
+i=i+1;f(i)=' int fd1, fd2, rv, exit_status;'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' if (fork() == 0) { /* Child */'
+i=i+1;f(i)=' if ((fd1 = pen(argv[1], O_RDONLY)) == -1)'
+i=i+1;f(i)=' quit('+ascii(34)+'Error in opening file for reading\n'+ascii(34)+', 1);'
+i=i+1;f(i)=' if ((fd2 = open(argv[2], OPENFLAGS, MODE600) == -1)'
+i=i+1;f(i)=' quit('+ascii(34)+'Error in opening file for writing\n'+ascii(34)+',1);'
+i=i+1;f(i)=' dup(fd1,0); /* Closes standard input simultaneously */'
+i=i+1;f(i)=' dup(fd2,1); /* Closes standard output simultaneously*/'
+i=i+1;f(i)=' execvp(argv[3], &argv[3]); /* Execute command */'
+i=i+1;f(i)=' quit('+ascii(34)+'exec error'+ascii(34)+', 2);'
+i=i+1;f(i)='} else { /*parent */'
+i=i+1;f(i)='wait(&rv); /* Or use waitpid(-1,&rv, 0) */'
+i=i+1;f(i)='printf('+ascii(34)+'Exit status: %d\n'+ascii(34)+',WEXITSTATUS(rv));'
+i=i+1;f(i)='}'
+i=i+1;f(i)='}'
+n=i
+
+
+
+printf("\n\n$ cat dup2.c # to open the file emp.lst")
+halt(' ')
+u=mopen('dup2.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 shell.c")
+ halt(' ')
+ printf("$ a.out /etc/passwd passwd.cnt grep joker")
+ halt(' ')
+ printf("Exit status: 1 # joker not found in /etc/passwd")
+ halt("a.out /etc/passwd passwd.cnt grep sumit")
+printf("Exit status: 0 # sumit found in /etc/passwd ")
+halt(' ')
+printf("$ cat passwd.cnt")
+halt(' ')
+printf("sumit:x:500:500:sumitabha das:/home/sumit:/bin/bash")
+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.11/Result11.txt b/1088/CH24/EX24.11/Result11.txt
new file mode 100755
index 000000000..6b49b4e04
--- /dev/null
+++ b/1088/CH24/EX24.11/Result11.txt
@@ -0,0 +1,93 @@
+ ans =
+
+ 1.
+
+-->exec('Example11.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 11 : Show the effect of opening files int the parent and the child to reassign descriptors
+
+ ****************************************************************
+
+ 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 dup2.c # to open the file emp.lst /* Program: dup2.c -- Opens files in the parent and uses dup2 in the child to reassign the descriptors */
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <wait.h>
+
+#define OPENFLAGS (O_WRONLY | O_CREAT | O_TRUNC)
+#define MODE600 (S_IRUSR | S_IWUSR)
+
+void quit(char *message, int exit_status) ;
+
+int main(int argc,char **argv) {
+ int fd1, fd2, rv, exit_status;
+
+ if (fork() == 0) { /* Child */
+ if ((fd1 = pen(argv[1], O_RDONLY)) == -1)
+ quit("Error in opening file for reading\n", 1);
+ if ((fd2 = open(argv[2], OPENFLAGS, MODE600) == -1)
+ quit("Error in opening file for writing\n",1);
+ dup(fd1,0); /* Closes standard input simultaneously */
+ dup(fd2,1); /* Closes standard output simultaneously*/
+ execvp(argv[3], &argv[3]); /* Execute command */
+ quit("exec error", 2);
+} else { /*parent */
+wait(&rv); /* Or use waitpid(-1,&rv, 0) */
+printf("Exit status: %d\n",WEXITSTATUS(rv));
+}
+}
+ $ cc dup2.c $ a.out /etc/passwd passwd.cnt grep joker Exit status: 1 # joker not found in /etc/passwda.out /etc/passwd passwd.cnt grep sumitExit status: 0 # sumit found in /etc/passwd $ cat passwd.cnt sumit:x:500:500:sumitabha das:/home/sumit:/bin/bash
+
+
+$ exit #To exit the current simulation terminal and return to Scilab console
+
+........# (hit [ENTER] for result)
+
+ BACK TO SCILAB CONSOLE...
+Loading initial environment
+
diff --git a/1088/CH24/EX24.12/Example12.sce b/1088/CH24/EX24.12/Example12.sce
new file mode 100755
index 000000000..d07acaca4
--- /dev/null
+++ b/1088/CH24/EX24.12/Example12.sce
@@ -0,0 +1,75 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 12 : Show the effect of sharing a pipe between two processes from parent to child \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: pipe.c -- Shares a pipe between two processes for data to flow from parent to child*/'
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='#include <unistd.h>'
+i=i+1;f(i)=''
+i=i+1;f(i)='void quit(char *, int);'
+i=i+1;f(i)='int main(void) {'
+i=i+1;f(i)=' int n,fd[2]; /* fd[2] to be filled up by pipe() */'
+i=i+1;f(i)=' char buf[100]; /* Buffer to be used by read() */'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' if (pipe(fd) < 0) /* fd[0] is read end */'
+i=i+1;f(i)=' quit('+ascii(34)+'pipe'+ascii(34)+',1); /* fd[1] is write end */'
+ i=i+1;f(i)=' '
+i=i+1;f(i)=' switch (fork()) { /* Pipe has four descriptors now */'
+i=i+1;f(i)=' case -1:quit('+ascii(34)+'Fork error'+ascii(34)+',2);'
+i=i+1;f(i)=' case 0:close(fd[1]); /* CHILD-Close write end of pipe */'
+i=i+1;f(i)=' n=read(fd[0],buf,100); /* and read from its read end */'
+i=i+1;f(i)=' write(STDOUT_FILENO,buf,n);'
+i=i+1;f(i)=' break;'
+i=i+1;f(i)=' default: close(fd[0]); /*PARENT-Close read end of pipe */'
+i=i+1;f(i)=' write(fd[1],'+ascii(34)+'Writing to pipe\n'+ascii(34)+', 16); /* write to write end */'
+i=i+1;f(i)=' }'
+i=i+1;f(i)=' exit(0);'
+i=i+1;f(i)='}'
+n=i
+
+
+printf("\n\n$ cat pipe.c # to open the file emp.lst")
+halt(' ')
+u=mopen('pipe.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 shell.c")
+ halt(' ')
+ printf("$ a.out ")
+ halt(' ')
+ printf("Writing to pipe")
+
+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.12/Result12.txt b/1088/CH24/EX24.12/Result12.txt
new file mode 100755
index 000000000..ebbb592dc
--- /dev/null
+++ b/1088/CH24/EX24.12/Result12.txt
@@ -0,0 +1,87 @@
+ ans =
+
+ 2.
+
+-->exec('Example12.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 12 : Show the effect of sharing a pipe between two processes from parent to child
+
+ ****************************************************************
+
+ 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 pipe.c # to open the file emp.lst /* Program: pipe.c -- Shares a pipe between two processes for data to flow from parent to child*/
+#include <stdio.h>
+#include <unistd.h>
+
+void quit(char *, int);
+int main(void) {
+ int n,fd[2]; /* fd[2] to be filled up by pipe() */
+ char buf[100]; /* Buffer to be used by read() */
+
+ if (pipe(fd) < 0) /* fd[0] is read end */
+ quit("pipe",1); /* fd[1] is write end */
+
+ switch (fork()) { /* Pipe has four descriptors now */
+ case -1:quit("Fork error",2);
+ case 0:close(fd[1]); /* CHILD-Close write end of pipe */
+ n=read(fd[0],buf,100); /* and read from its read end */
+ write(STDOUT_FILENO,buf,n);
+ break;
+ default: close(fd[0]); /*PARENT-Close read end of pipe */
+ write(fd[1],"Writing to pipe\n", 16); /* write to write end */
+ }
+ exit(0);
+}
+ $ cc shell.c $ a.out Writing to pipe
+
+
+$ 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)
diff --git a/1088/CH24/EX24.13/Example13.sce b/1088/CH24/EX24.13/Example13.sce
new file mode 100755
index 000000000..c38922d79
--- /dev/null
+++ b/1088/CH24/EX24.13/Example13.sce
@@ -0,0 +1,77 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 13 : Show the method of running two programs in a pileline \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 pipe2.c -- Runs two programs in a pipeline Child runs cat, parent runs tr */'
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='#include <unistd.h>'
+i=i+1;f(i)=''
+i=i+1;f(i)='void quit(char *message,int exit_status);'
+i=i+1;f(i)='int main(void) { '
+i=i+1;f(i)=' int fd[2]; /* To be fille dup by pipe() */'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' if (pipe(fd) < 0) /* Now have four descriptors for pipe */'
+i=i+1;f(i)=' quit('+ascii(34)+'pipe'+ascii(34)+', 1);'
+i=i+1;f(i)=' switch (fork()) {'
+i=i+1;f(i)=' case -1: quit('+ascii(34)+'fork'+ascii(34)+', 2);'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' case 0: close(fd[0]); /* CHILD - Close read end first */'
+i=i+1;f(i)=' dup2(fd[1], STDOUT_FILENO); /* Connect stdout to write end */'
+i=i+1;f(i)=' close(fd[1]); /* and close original descriptor */'
+ i=i+1;f(i)=' execlp('+ascii(34)+'cat'+ascii(34)+', '+ascii(34)+'cat'+ascii(34)+','+ascii(34)+'/etc/hosts.equiv'+ascii(34)+', (char *) 0);'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' default: close(fd[1]); /* PARENT -- Close write end first */'
+i=i+1;f(i)=' dup2(fd[0], STDIN_FILENO); /* Connect stdin to read end */'
+i=i+1;f(i)=' close(fd[0]); /* and close original descriptor */'
+i=i+1;f(i)=' execlp('+ascii(34)+'tr'+ascii(34)+', '+ascii(34)+'tr'+ascii(34)+', '+ascii(34)+''+ascii(39)+'[a-z]'+ascii(39)+''+ascii(34)+','+ascii(34)+''+ascii(39)+'[A-Z]'+ascii(39)+''+ascii(34)+',(char *) 0);'
+i=i+1;f(i)=' quit('+ascii(34)+'tr'+ascii(34)+', 4);'
+i=i+1;f(i)='}'
+i=i+1;f(i)='}'
+n=i
+
+
+printf("\n\n$ cat pipe2.c # to open the file emp.lst")
+halt(' ')
+u=mopen('pipe2.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 shell.c")
+ halt(' ')
+ printf("$ a.out ")
+ halt(' ')
+ printf("SATURN\nEARTH\nMERCURY\nJUPITER\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.13/Result13.txt b/1088/CH24/EX24.13/Result13.txt
new file mode 100755
index 000000000..7d3ae5751
--- /dev/null
+++ b/1088/CH24/EX24.13/Result13.txt
@@ -0,0 +1,93 @@
+ ans =
+
+ 1.
+
+-->exec('Example13.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 13 : Show the method of running two programs in a pileline
+
+ ****************************************************************
+
+ 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 pipe2.c # to open the file emp.lst /* Program pipe2.c -- Runs two programs in a pipeline Child runs cat, parent runs tr */
+#include <stdio.h>
+#include <unistd.h>
+
+void quit(char *message,int exit_status);
+int main(void) {
+ int fd[2]; /* To be fille dup by pipe() */
+
+ if (pipe(fd) < 0) /* Now have four descriptors for pipe */
+ quit("pipe", 1);
+ switch (fork()) {
+ case -1: quit("fork", 2);
+
+ case 0: close(fd[0]); /* CHILD - Close read end first */
+ dup2(fd[1], STDOUT_FILENO); /* Connect stdout to write end */
+ close(fd[1]); /* and close original descriptor */
+ execlp("cat", "cat","/etc/hosts.equiv", (char *) 0);
+
+ default: close(fd[1]); /* PARENT -- Close write end first */
+ dup2(fd[0], STDIN_FILENO); /* Connect stdin to read end */
+ close(fd[0]); /* and close original descriptor */
+ execlp("tr", "tr", "'[a-z]'","'[A-Z]'",(char *) 0);
+ quit("tr", 4);
+}
+}
+ $ cc pipe2.c $ a.out SATURN
+EARTH
+MERCURY
+JUPITER
+
+
+
+$ 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)
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)
diff --git a/1088/CH24/EX24.15/Example15.sce b/1088/CH24/EX24.15/Example15.sce
new file mode 100755
index 000000000..ab39ecc56
--- /dev/null
+++ b/1088/CH24/EX24.15/Example15.sce
@@ -0,0 +1,93 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 15 : Show the effect of [Ctrl-c] in the shell so as to do some operations \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: signal2.c -- Handles SIGINT and SIGTSTP generated from terminal Required two [Ctrl-c]s to terminate */'+ascii(39)+''
+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)=''
+i=i+1;f(i)='void quit(char *message, int exit_status) ;'
+i=i+1;f(i)='void tstp_handler(int signo); /* Handler for [Ctrl-z] */'
+i=i+1;f(i)='void int_handler(int signo); /* Handler for [Ctrl-c] */'
+i=i+1;f(i)='int n, count=0;'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(void) {'
+i=i+1;f(i)=' signal(SIGTSTP, tstp_handler); /* Disposition for these two signals */'
+i=i+1;f(i)=' signal(SIGINT, int_handler); /* set to enter respective handler */'
+i=i+1;f(i)=' signal(SIGQUIT, SIG_IGN); /* Disposition set to ignore */'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' fprintf(stderr,'+ascii(34)+'Press [Ctrl-z] first, then [Ctrl-c]\n'+ascii(34)+');'
+i=i+1;f(i)=' for(;;)'
+i=i+1;f(i)=' pause(); /* Will return on reciept of help */'
+i=i+1;f(i)='}'
+i=i+1;f(i)=''
+i=i+1;f(i)='void tstp_handler(int signo) {'
+i=i+1;f(i)=' signal(SIGTSTP, tstp_handler); /* Not entirely reliable */'
+i=i+1;f(i)=' fprintf(stderr, '+ascii(34)+'Can'+ascii(39)+'t stop this program\n'+ascii(34)+'); /* same signal can reset */'
+i=i+1;f(i)='} /* disposition to default */'
+i=i+1;f(i)=''
+i=i+1;f(i)='void int_handler(int signo) { /* Will terminate program */'
+i=i+1;f(i)=' signal(SIGINT, int_handler); /* on second invocation */'
+i=i+1;f(i)=' (++count == 1) ? printf('+ascii(34)+'Press again\n'+ascii(34)+') : quit('+ascii(34)+'Quitting'+ascii(34)+', 1);'
+n=i
+
+
+
+printf("\n\n$ cat signal2.c # to open the file emp.lst")
+halt(' ')
+u=mopen('signal2.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 signal2.c")
+ halt(' ')
+ printf("$ a.out ")
+ halt(' ')
+printf("Press [Ctrl-z] first, then [Ctrl-c]")
+halt("")
+printf("# [Ctrl - \\] pressed ")
+sleep(2500)
+printf(" Signal Ignored \n")
+printf("# [Ctrl - z] pressed \n")
+sleep(2500)
+printf("Cannot stop this program From tstp_handler\n")
+printf("# [Ctrl - c] pressed ")
+sleep(2500)
+printf("\nPress again From int_handler\n")
+printf("# [Ctrl - c] pressed \n")
+sleep(2500)
+printf("Quitting: Interrupted system call From int_handler")
+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.15/Result15.txt b/1088/CH24/EX24.15/Result15.txt
new file mode 100755
index 000000000..ec0989385
--- /dev/null
+++ b/1088/CH24/EX24.15/Result15.txt
@@ -0,0 +1,98 @@
+ ans =
+
+ 1.
+
+-->exec('Example15.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 15 : Show the effect of [Ctrl-c] in the shell so as to do some operations
+
+ ****************************************************************
+
+ 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 signal2.c # to open the file emp.lst /* Program: signal2.c -- Handles SIGINT and SIGTSTP generated from terminal Required two [Ctrl-c]s to terminate */'
+#include <stdio.h>
+#include <unistd.h>
+#include <signal.h>
+
+void quit(char *message, int exit_status) ;
+void tstp_handler(int signo); /* Handler for [Ctrl-z] */
+void int_handler(int signo); /* Handler for [Ctrl-c] */
+int n, count=0;
+
+int main(void) {
+ signal(SIGTSTP, tstp_handler); /* Disposition for these two signals */
+ signal(SIGINT, int_handler); /* set to enter respective handler */
+ signal(SIGQUIT, SIG_IGN); /* Disposition set to ignore */
+
+ fprintf(stderr,"Press [Ctrl-z] first, then [Ctrl-c]\n");
+ for(;;)
+ pause(); /* Will return on reciept of help */
+}
+
+void tstp_handler(int signo) {
+ signal(SIGTSTP, tstp_handler); /* Not entirely reliable */
+ fprintf(stderr, "Can't stop this program\n"); /* same signal can reset */
+} /* disposition to default */
+
+void int_handler(int signo) { /* Will terminate program */
+ signal(SIGINT, int_handler); /* on second invocation */
+ (++count == 1) ? printf("Press again\n") : quit("Quitting", 1);
+ $ cc signal2.c $ a.out Press [Ctrl-z] first, then [Ctrl-c]# [Ctrl - \] pressed Signal Ignored
+# [Ctrl - z] pressed
+Cannot stop this program From tstp_handler
+# [Ctrl - c] pressed
+Press again From int_handler
+# [Ctrl - c] pressed
+Quitting: Interrupted system call From int_handler
+
+
+$ 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)
diff --git a/1088/CH24/EX24.16/Example16.sce b/1088/CH24/EX24.16/Example16.sce
new file mode 100755
index 000000000..56ba0d218
--- /dev/null
+++ b/1088/CH24/EX24.16/Example16.sce
@@ -0,0 +1,109 @@
+clear
+flag=1
+mode(-1)
+clc
+//Program for example 1 chapter 1
+printf("Current date is %s \n \nWelcome to the Textbook Companionship Project 2013 \n",date())
+printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n")
+disp("Book Title : UNIX CONCEPTS AND APPLICATIONS ")
+disp("Book Edition : 4")
+disp("Book Author : Sumitabha Das")
+printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n")
+disp("Code Author : Pranav Bhat T")
+printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n")
+disp("Chapter Number : 24")
+disp("Chapter Title : Systems programming II- Files")
+printf("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n"
+printf("Example 16 : Show the method of using fork and exec to run a user-defined\n program and kill it in 5 seconds if not completed \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: killprocess.c -- Uses fork and exec to run a user-defined program and kills it if it doesnt complete in 5 seconds */'
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='#include <sys/types.h>'
+i=i+1;f(i)='#include <sys/wait.h>'
+i=i+1;f(i)='#include <signal.h>'
+i=i+1;f(i)=''
+i=i+1;f(i)='pid_t pid;'
+i=i+1;f(i)='int main(int argc, char **argv) {'
+i=i+1;f(i)=' int i,status;'
+i=i+1;f(i)=' void death_handler(int signo); /* A common signal handler this time */'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' signal(SIGCHLD, death_handler); /* death_handler is invoked when a */'
+i=i+1;f(i)=' signal(SIGALRM, death_handler); /* child dies or an alarm is recieved */'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' switch (pid = fork()) {'
+i=i+1;f(i)=' case -1: printf('+ascii(34)+'Fork error\n'+ascii(34)+');'
+i=i+1;f(i)=' case 0: execvp(argv[1],&argv[1]); /* Execute command */'
+i=i+1;f(i)=' perror('+ascii(34)+'exec'+ascii(34)+');'
+i=i+1;f(i)=' break;'
+i=i+1;f(i)=' default: alarm(5); /* Will send SIGALRM after 5 seconds */'
+i=i+1;f(i)=' pause(); /* Will return when SIGCHILD signal is received */'
+i=i+1;f(i)=' printf('+ascii(34)+'Parent dies\n'+ascii(34)+');'
+i=i+1;f(i)=' }'
+i=i+1;f(i)=' exit(0);'
+i=i+1;f(i)=' }'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' void death_handler(int signo) { /* This common handler pics up the */'
+i=i+1;f(i)=' int status; /* exit status for normal termination */'
+i=i+1;f(i)=' signal(signo, death_handler); /* but sends the SIGTERM signal if */'
+i=i+1;f(i)=' switch(signo) { /* command doesnt complete in 5 seconds */'
+i=i+1;f(i)=' case SIGCHLD: waitpid(-1, &status, 0); /* Same as wait(&status); */'
+i=i+1;f(i)=' printf('+ascii(34)+'Child dies; exit status: %d\n'+ascii(34)+',WEXITSTATUS(status));'
+i=i+1;f(i)=' break;'
+i=i+1;f(i)=' case SIGALRM: if (kill(pid, SIGTERM) == 0)'
+i=i+1;f(i)=' fprintf(stderr, '+ascii(34)+'5 seconds over,child killed\n'+ascii(34)+');'
+i=i+1;f(i)=' }'
+i=i+1;f(i)='}'
+n=i
+
+
+printf("\n\n$ cat killprocess.c # to open the file emp.lst")
+halt(' ')
+u=mopen('killprocess.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 killprocess.c")
+ halt(' ')
+ printf("$ a.out date")
+ halt(' ')
+ printf("Sat Jun 20 22:29:27 IST 2013\nChild dies: exit status: 0\nParent dies")
+halt(' ')
+printf("\n")
+printf("$ a.out find /home -name a.out -print")
+halt(' ')
+printf("/home /sumit/personal/project8/a.out\n/home/sumit/personal/books_code/glass_ables/12/a.out\n/home/sumit/personal/books_code/stevens_c/ch08/a.out")
+printf(" ..after 5 second time interval ...")
+sleep(5000)
+printf("\n5 seconds over, child killed\nParent dies\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.16/Result16.txt b/1088/CH24/EX24.16/Result16.txt
new file mode 100755
index 000000000..2225a189d
--- /dev/null
+++ b/1088/CH24/EX24.16/Result16.txt
@@ -0,0 +1,110 @@
+ ans =
+
+ 1.
+
+-->exec('Example16.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 16 : Show the method of using fork and exec to run a user-defined
+ program and kill it in 5 seconds if not completed
+
+ ****************************************************************
+
+ 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 killprocess.c # to open the file emp.lst /* Program: killprocess.c -- Uses fork and exec to run a user-defined program and kills it if it doesnt complete in 5 seconds */
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <signal.h>
+
+pid_t pid;
+int main(int argc, char **argv) {
+ int i,status;
+ void death_handler(int signo); /* A common signal handler this time */
+
+ signal(SIGCHLD, death_handler); /* death_handler is invoked when a */
+ signal(SIGALRM, death_handler); /* child dies or an alarm is recieved */
+
+ switch (pid = fork()) {
+ case -1: printf("Fork error\n");
+ case 0: execvp(argv[1],&argv[1]); /* Execute command */
+ perror("exec");
+ break;
+ default: alarm(5); /* Will send SIGALRM after 5 seconds */
+ pause(); /* Will return when SIGCHILD signal is received */
+ printf("Parent dies\n");
+ }
+ exit(0);
+ }
+
+ void death_handler(int signo) { /* This common handler pics up the */
+ int status; /* exit status for normal termination */
+ signal(signo, death_handler); /* but sends the SIGTERM signal if */
+ switch(signo) { /* command doesnt complete in 5 seconds */
+ case SIGCHLD: waitpid(-1, &status, 0); /* Same as wait(&status); */
+ printf("Child dies; exit status: %d\n",WEXITSTATUS(status));
+ break;
+ case SIGALRM: if (kill(pid, SIGTERM) == 0)
+ fprintf(stderr, "5 seconds over,child killed\n");
+ }
+}
+ $ cc killprocess.c $ a.out date Sat Jun 20 22:29:27 IST 2013
+Child dies: exit status: 0
+Parent dies
+$ a.out find /home -name a.out -print /home /sumit/personal/project8/a.out
+/home/sumit/personal/books_code/glass_ables/12/a.out
+/home/sumit/personal/books_code/stevens_c/ch08/a.out ..after 5 second time interval ...
+5 seconds over, child killed
+Parent dies
+
+
+
+$ 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)
diff --git a/1088/CH24/EX24.2/Example2.sce b/1088/CH24/EX24.2/Example2.sce
new file mode 100755
index 000000000..32a03a740
--- /dev/null
+++ b/1088/CH24/EX24.2/Example2.sce
@@ -0,0 +1,74 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 2 : Show the method of showing PID,PPID in both parent and child process \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: fork.c -- A simple fork Shows PID,PPID in both parent and child*/'
+i=i+1;f(i)=''
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='#include <sys/types.h>'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(void) {'
+i=i+1;f(i)=' pid_t pid;'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' printf('+ascii(34)+'Before forking\n'+ascii(34)+');'
+i=i+1;f(i)=' pid = fork(); /* Replicates current processes */'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' if(pid >0) { /* In the parent process; make sure */'
+i=i+1;f(i)=' sleep(1); /* That the parent does not die before child */'
+i=i+1;f(i)=' printf('+ascii(34)+'PARENT -- PID: %d PPID %d, CHILD PID: %d\n'+ascii(34)+',getpid(),getppid(),pid);}'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' else if (pid == 0) /* In the child process */'
+i=i+1;f(i)=' printf('+ascii(34)+'CHILD -- PID: %d PPID: %d\n'+ascii(34)+',getpid(),getppid());'
+i=i+1;f(i)=' else { /* pid must be -1 here */'
+i=i+1;f(i)=' printf('+ascii(34)+'Fork error\n'+ascii(34)+');'
+i=i+1;f(i)=' exit(1);}'
+i=i+1;f(i)=' printf('+ascii(34)+'Both process continue from here\n'+ascii(34)+'); /* In both processes */'
+i=i+1;f(i)=' exit(0);'
+i=i+1;f(i)='}'
+n=i
+
+printf("\n\n$ cat fork.c # to open the file emp.lst")
+halt(' ')
+u=mopen('fork.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 fork.c")
+ halt(' ')
+ printf("$ a.out")
+ halt(' ')
+ printf("Before forking\nCHILD -- PID: 1556 PPID: 1555\nBoth processes continue from here # This statement runs in child\nPARENT -- PID: 1555 PPID: 1450,CHILD PID: 1556\nBoth processes continue from here ...as well as in parent\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.2/Result2.txt b/1088/CH24/EX24.2/Result2.txt
new file mode 100755
index 000000000..38007bf78
--- /dev/null
+++ b/1088/CH24/EX24.2/Result2.txt
@@ -0,0 +1,92 @@
+ ans =
+
+ 1.
+
+-->exec('Example2.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 : 23
+
+ Chapter Title : Systems programming II- Files
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+Example 2 : Show the method of showing PID,PPID in both parent and child process
+
+ ****************************************************************
+
+ 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 fork.c # to open the file emp.lst /* Program: fork.c -- A simple fork Shows PID,PPID in both parent and child*/
+
+#include <stdio.h>
+#include <sys/types.h>
+
+int main(void) {
+ pid_t pid;
+
+ printf("Before forking\n");
+ pid = fork(); /* Replicates current processes */
+
+ if(pid >0) { /* In the parent process; make sure */
+ sleep(1); /* That the parent does not die before child */
+ printf("PARENT -- PID: %d PPID %d, CHILD PID: %d\n",getpid(),getppid(),pid);}
+
+ else if (pid == 0) /* In the child process */
+ printf("CHILD -- PID: %d PPID: %d\n",getpid(),getppid());
+ else { /* pid must be -1 here */
+ printf("Fork error\n");
+ exit(1);}
+ printf("Both process continue from here\n"); /* In both processes */
+ exit(0);
+}
+ $ cc fork.c $ a.out Before forking
+CHILD -- PID: 1556 PPID: 1555
+Both processes continue from here # This statement runs in child
+PARENT -- PID: 1555 PPID: 1450,CHILD PID: 1556
+Both processes continue from here ...as well as in parent
+
+
+
+$ 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)
diff --git a/1088/CH24/EX24.3/Example3.sce b/1088/CH24/EX24.3/Example3.sce
new file mode 100755
index 000000000..5c4fc8e34
--- /dev/null
+++ b/1088/CH24/EX24.3/Example3.sce
@@ -0,0 +1,101 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 3 : Show the effect of changing the childs environment and check its effect in parent \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: childenv.c -- Changes child'+ascii(39)+'s environment and then checks the effect in parent*/'
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='#include <sys/types.h>'
+i=i+1;f(i)='#define PATH_LENGTH 30'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(void) {'
+i=i+1;f(i)=' pid_t pid;'
+i=i+1;f(i)=' int x = 100;'
+i=i+1;f(i)=' char newdir[PATH_LENGTH + 1]; /* Additional space required for \0*/'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' getcwd(newdir, PATH_LENGTH); /* Get current directory before fork */'
+i=i+1;f(i)=' printf('+ascii(34)+'BEFORE FORK -- Current directory: %s\n'+ascii(34)+', newdir);'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' pid = fork ();'
+i=i+1;f(i)=' switch (pid) {'
+i=i+1;f(i)=' case -1:'
+i=i+1;f(i)=' perror('+ascii(34)+'fork'+ascii(34)+');'
+i=i+1;f(i)=' exit(1); /*for error*/'
+i=i+1;f(i)=' case 0: /*Child*/'
+i=i+1;f(i)=' printf('+ascii(34)+'CHILD -- Inherited value of x: %d\n'+ascii(34)+', x);'
+i=i+1;f(i)=' x=200;'
+i=i+1;f(i)=' printf('+ascii(34)+'CHILD -- Changed value of x: %d\n'+ascii(34)+', x);'
+i=i+1;f(i)=' printf('+ascii(34)+'CHILD -- Inherited value of PATH: %s\n'+ascii(34)+', getenv('+ascii(34)+'PATH'+ascii(34)+'));'
+i=i+1;f(i)=' setenv('+ascii(34)+'PATH'+ascii(34)+','+ascii(34)+'.'+ascii(34)+', 1); /* Change PATH here; use putenv('+ascii(34)+'PATH=.'+ascii(34)+') */'
+i=i+1;f(i)=' /* if setenv() not supported */'
+i=i+1;f(i)=' printf('+ascii(34)+'CHILD -- New value of PATH: %s\n'+ascii(34)+', getenv('+ascii(34)+'PATH'+ascii(34)+'));'
+i=i+1;f(i)=' if (chdir('+ascii(34)+'/etc'+ascii(34)+') != -) { /* '+ascii(34)+'cd'+ascii(34)+' to /etc */'
+i=i+1;f(i)=' getcwd(newdir, PATH_LENGTH); /* Do a '+ascii(34)+'pwd'+ascii(34)+' */'
+i=i+1;f(i)=' printf('+ascii(34)+'CHILD -- Current directory changed to: %s\n'+ascii(34)+',newdir);'
+i=i+1;f(i)=' }'
+i=i+1;f(i)=' break;'
+i=i+1;f(i)=' exit(0);'
+i=i+1;f(i)=' default:/* Parent */'
+i=i+1;f(i)=' sleep(2); /* Allow child to complete */'
+i=i+1;f(i)=' getcwd(newdir, PATH_LENGTH); /*Getting new directory */'
+i=i+1;f(i)=' printf('+ascii(34)+'PARENT -- Value of x after change by child: %d\n'+ascii(34)+',x);'
+i=i+1;f(i)=' printf('+ascii(34)+'PARENT -- Current directory is still: %s\n'+ascii(34)+', newdir);'
+i=i+1;f(i)=' printf('+ascii(34)+'PARENT -- Value of PATH is unchanged: %s\n'+ascii(34)+',getenv('+ascii(34)+'PATH'+ascii(34)+'));'
+i=i+1;f(i)=' exit(0);'
+i=i+1;f(i)='}'
+i=i+1;f(i)='}'
+n=i
+
+
+printf("\n\n$ cat childenv.c # to open the file emp.lst")
+halt(' ')
+u=mopen('childenv.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 childenv.c")
+ halt(' ')
+ printf("$ a.out")
+ halt(' ')
+ printf("BEFORE FORK -- Current directory: /users1/home/staff/sumit")
+ printf("\nCHILD -- Inherited value of x: 100")
+ printf("\nCHILD -- Changed value of x:200")
+ printf("\nCHILD -- Inherited value of PATH: /usr/bin::/usr/local/bin:/usr/ccs/bin")
+ printf("\nCHILD -- New value of PATH: .")
+ printf("\nCHILD -- Current directory changed to: /etc")
+ printf("\nPARENT -- Value of x after change to child: 100")
+ printf("\nPARENT -- Current directory is still: /users1/home/staff/sumit")
+ printf("\nPARENT -- Value of PATH is unchanged: /usr/bin::/usr/local/bin::/usr/ccs/bin")
+ 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.3/Result3.txt b/1088/CH24/EX24.3/Result3.txt
new file mode 100755
index 000000000..d27c2b578
--- /dev/null
+++ b/1088/CH24/EX24.3/Result3.txt
@@ -0,0 +1,115 @@
+ ans =
+
+ 1.
+
+
+-->exec('Example3.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 3 : Show the effect of changing the childs environment and check its effect in parent
+
+ ****************************************************************
+
+ 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 childenv.c # to open the file emp.lst /* Program: childenv.c -- Changes child's environment and then checks the effect in parent*/
+#include <stdio.h>
+#include <sys/types.h>
+#define PATH_LENGTH 30
+
+int main(void) {
+ pid_t pid;
+ int x = 100;
+ char newdir[PATH_LENGTH + 1]; /* Additional space required for \0*/
+
+ getcwd(newdir, PATH_LENGTH); /* Get current directory before fork */
+ printf("BEFORE FORK -- Current directory: %s\n", newdir);
+
+ pid = fork ();
+ switch (pid) {
+ case -1:
+ perror("fork");
+ exit(1); /*for error*/
+ case 0: /*Child*/
+ printf("CHILD -- Inherited value of x: %d\n", x);
+ x=200;
+ printf("CHILD -- Changed value of x: %d\n", x);
+ printf("CHILD -- Inherited value of PATH: %s\n", getenv("PATH"));
+ setenv("PATH",".", 1); /* Change PATH here; use putenv("PATH=.") */
+ /* if setenv() not supported */
+ printf("CHILD -- New value of PATH: %s\n", getenv("PATH"));
+ if (chdir("/etc") != -) { /* "cd" to /etc */
+ getcwd(newdir, PATH_LENGTH); /* Do a "pwd" */
+ printf("CHILD -- Current directory changed to: %s\n",newdir);
+ }
+ break;
+ exit(0);
+ default:/* Parent */
+ sleep(2); /* Allow child to complete */
+ getcwd(newdir, PATH_LENGTH); /*Getting new directory */
+ printf("PARENT -- Value of x after change by child: %d\n",x);
+ printf("PARENT -- Current directory is still: %s\n", newdir);
+ printf("PARENT -- Value of PATH is unchanged: %s\n",getenv("PATH"));
+ exit(0);
+}
+}
+ $ cc childenv.c $ a.out BEFORE FORK -- Current directory: /users1/home/staff/sumit
+CHILD -- Inherited value of x: 100
+CHILD -- Changed value of x:200
+CHILD -- Inherited value of PATH: /usr/bin::/usr/local/bin:/usr/ccs/bin
+CHILD -- New value of PATH: .
+CHILD -- Current directory changed to: /etc
+PARENT -- Value of x after change to child: 100
+PARENT -- Current directory is still: /users1/home/staff/sumit
+PARENT -- Value of PATH is unchanged: /usr/bin::/usr/local/bin::/usr/ccs/bin
+
+
+$ 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)
diff --git a/1088/CH24/EX24.4/Example4.sce b/1088/CH24/EX24.4/Example4.sce
new file mode 100755
index 000000000..1f362959f
--- /dev/null
+++ b/1088/CH24/EX24.4/Example4.sce
@@ -0,0 +1,82 @@
+clear
+flag=1
+mode(-1)
+
+printf("Example 4 : Show the effect of obtaining child termination status by WEXITSTATUS \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: wait.c -- Uses wait to obtain child'+ascii(39)+'s termination status.The WEXITSTATUS macro fetches the exit status */'
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='#include <fcntl.h>'
+i=i+1;f(i)='#include <sys/wait.h>'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(int argc, char **argv) {'
+i=i+1;f(i)=' int fd,exitstatus;'
+i=i+1;f(i)=' int exitval = 10; /* Value to be returned by child */'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' fd= open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);'
+i=i+1;f(i)=' write(fd, '+ascii(34)+'Original process writes\n'+ascii(34)+',24); /* First write */'
+ i=i+1;f(i)=''
+i=i+1;f(i)=' switch(fork()) {'
+i=i+1;f(i)=' case 0:'
+i=i+1;f(i)=' write(fd,'+ascii(34)+'Child writes\n'+ascii(34)+',13); /* Second write */'
+i=i+1;f(i)=' close(fd); /*Closing here doesn'+ascii(39)+'t affect parent'+ascii(39)+'s copy */'
+i=i+1;f(i)=' printf('+ascii(34)+'CHILD: Terminating with exit value %d\n'+ascii(34)+', exitval);'
+i=i+1;f(i)=' exit(exitval); /* Can also use_exit(exitval) */'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' default:'
+i=i+1;f(i)=' wait(&exitstatus); /* Waits for child to die */'
+i=i+1;f(i)=' printf('+ascii(34)+'PARENT: Child terminated with exit value %d\n'+ascii(34)+',WEXITSTATUS(exitstatus));'
+i=i+1;f(i)=' /*Extracting exit status */'
+i=i+1;f(i)=' write(fd, '+ascii(34)+'Parent writes\n'+ascii(34)+', 14); /* Third write */'
+i=i+1;f(i)=' exit(20); /* Value returned to shell; try echo $? */'
+i=i+1;f(i)=' }'
+i=i+1;f(i)='}'
+n=i
+
+
+printf("\n\n$ cat wait.c # to open the file ")
+halt(' ')
+u=mopen('wait.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 wait.c")
+ halt(' ')
+ printf("$ a.out foo")
+ halt(' ')
+ printf("CHILD: Terminating with exit value 10\nPARENT: Child terminated with exit value 10\n")
+ halt(' ')
+ printf("$ cat foo ")
+ halt(' ')
+ printf("Original process writes\nChild writes\nParent writes\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.4/Result4.txt b/1088/CH24/EX24.4/Result4.txt
new file mode 100755
index 000000000..1d3d913d7
--- /dev/null
+++ b/1088/CH24/EX24.4/Result4.txt
@@ -0,0 +1,96 @@
+ ans =
+
+ 1.
+
+-->exec('Example4.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 4 : Show the effect of obtaining child termination status by WEXITSTATUS
+
+ ****************************************************************
+
+ 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 wait.c # to open the file /* Program: wait.c -- Uses wait to obtain child's termination status.The WEXITSTATUS macro fetches the exit status */
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/wait.h>
+
+int main(int argc, char **argv) {
+ int fd,exitstatus;
+ int exitval = 10; /* Value to be returned by child */
+
+ fd= open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ write(fd, "Original process writes\n",24); /* First write */
+
+ switch(fork()) {
+ case 0:
+ write(fd,"Child writes\n",13); /* Second write */
+ close(fd); /*Closing here doesn't affect parent's copy */
+ printf("CHILD: Terminating with exit value %d\n", exitval);
+ exit(exitval); /* Can also use_exit(exitval) */
+
+ default:
+ wait(&exitstatus); /* Waits for child to die */
+ printf("PARENT: Child terminated with exit value %d\n",WEXITSTATUS(exitstatus));
+ /*Extracting exit status */
+ write(fd, "Parent writes\n", 14); /* Third write */
+ exit(20); /* Value returned to shell; try echo $? */
+ }
+}
+ $ cc wait.c $ a.out foo CHILD: Terminating with exit value 10
+PARENT: Child terminated with exit value 10
+ $ cat foo Original process writes
+Child writes
+Parent writes
+
+
+
+$ 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)
diff --git a/1088/CH24/EX24.5/Example5.sce b/1088/CH24/EX24.5/Example5.sce
new file mode 100755
index 000000000..882b7c003
--- /dev/null
+++ b/1088/CH24/EX24.5/Example5.sce
@@ -0,0 +1,70 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 5 : Show the effect of creating an orphan by letting child sleep for 2 minutes where parent dies immediately \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: orphan.c -- Creates an orphan by letting child sleep for 2 minutes.'
+i=i+1;f(i)=' Parent doesn'+ascii(39)+'t call wait and dies immediately */'
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='int main(void) {'
+i=i+1;f(i)=' int pid;'
+i=i+1;f(i)=' if ((pid = fork()) > 0) /* Parent */'
+i=i+1;f(i)=' exit(10); /* Parent exits without calling wait */'
+i=i+1;f(i)=' else if (pid == 0) { /* Child */'
+i=i+1;f(i)=' sleep(2); /* Lets parent die in this time frame */'
+i=i+1;f(i)=' printf('+ascii(34)+'CHILD: Adopted by init now, PPID: %d\n'+ascii(34)+',getppid());'
+i=i+1;f(i)=' exit(0);'
+i=i+1;f(i)='}'
+i=i+1;f(i)='}'
+n=i
+
+
+printf("\n\n$ cat orphan.c # to open the file emp.lst")
+halt(' ')
+u=mopen('orphan.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 orphan.c")
+ halt(' ')
+ printf("$ a.out ....no response for 2 seconds...")
+ halt(' ')
+ sleep(2000)
+ printf("CHILD: Adopted by init now, PPID: 1")
+ halt(' ')
+ printf("$ echo $?")
+ halt(' ')
+ printf("10")
+ 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.5/Result5.txt b/1088/CH24/EX24.5/Result5.txt
new file mode 100755
index 000000000..41320509a
--- /dev/null
+++ b/1088/CH24/EX24.5/Result5.txt
@@ -0,0 +1,77 @@
+ ans =
+
+ 1.
+
+-->exec('Example5.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 5 : Show the effect of creating an orphan by letting child sleep for 2 minutes where parent dies immediately
+
+ ****************************************************************
+
+ 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 orphan.c # to open the file emp.lst /* Program: orphan.c -- Creates an orphan by letting child sleep for 2 minutes.
+ Parent doesn't call wait and dies immediately */
+#include <stdio.h>
+int main(void) {
+ int pid;
+ if ((pid = fork()) > 0) /* Parent */
+ exit(10); /* Parent exits without calling wait */
+ else if (pid == 0) { /* Child */
+ sleep(2); /* Lets parent die in this time frame */
+ printf("CHILD: Adopted by init now, PPID: %d\n",getppid());
+ exit(0);
+}
+}
+ $ cc orphan.c $ a.out ....no response for 2 seconds... CHILD: Adopted by init now, PPID: 1 $ echo $? 10
+
+
+$ 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)
diff --git a/1088/CH24/EX24.6/Example6.sce b/1088/CH24/EX24.6/Example6.sce
new file mode 100755
index 000000000..8df7f427e
--- /dev/null
+++ b/1088/CH24/EX24.6/Example6.sce
@@ -0,0 +1,58 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 6 : Show the effect of using the execl series \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: execl.c -- Uses execl to run wc */'
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='int main(void) {'
+i=i+1;f(i)=' execl('+ascii(34)+'/bin/wc'+ascii(34)+','+ascii(34)+'wc'+ascii(34)+','+ascii(34)+'-l'+ascii(34)+','+ascii(34)+'-c'+ascii(34)+','+ascii(34)+'/etc/passwd'+ascii(34)+',(char*) 0);'
+i=i+1;f(i)=' printf('+ascii(34)+'execl error\n'+ascii(34)+');'
+i=i+1;f(i)='}'
+n=i
+
+
+printf("\n\n$ cat execl.c # to open the file emp.lst")
+halt(' ')
+u=mopen('execl.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 execl.c")
+ halt(' ')
+ printf("$ a.out ")
+ halt(' ')
+ printf(" 166 9953 /etc/passwd")
+ 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.6/Result6.txt b/1088/CH24/EX24.6/Result6.txt
new file mode 100755
index 000000000..027d42770
--- /dev/null
+++ b/1088/CH24/EX24.6/Result6.txt
@@ -0,0 +1,70 @@
+ ans =
+
+ 1.
+
+-->exec('Example6.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 6 : Show the effect of using the execl series
+
+ ****************************************************************
+
+ 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 execl.c # to open the file emp.lst /* Program: execl.c -- Uses execl to run wc */
+#include <stdio.h>
+int main(void) {
+ execl("/bin/wc","wc","-l","-c","/etc/passwd",(char*) 0);
+ printf("execl error\n");
+}
+ $ cc execl.c $ a.out 166 9953 /etc/passwd
+
+
+$ 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)
diff --git a/1088/CH24/EX24.7/Example7.sce b/1088/CH24/EX24.7/Example7.sce
new file mode 100755
index 000000000..5086606b5
--- /dev/null
+++ b/1088/CH24/EX24.7/Example7.sce
@@ -0,0 +1,61 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 7 : Show the effect of using the execv series \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: execv.c -- Stuffs all command line arguments to an an array to be used with execv */'
+i=i+1;f(i)=''
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='int main(int argc, char **argv) {'
+i=i+1;f(i)=' char *cmdargs[] = { '+ascii(34)+'grep'+ascii(34)+', '+ascii(34)+'-i'+ascii(34)+', '+ascii(34)+'-n'+ascii(34)+', '+ascii(34)+'SUMIT'+ascii(34)+', '+ascii(34)+'/etc/passwd'+ascii(34)+', NULL };'
+i=i+1;f(i)=' execv('+ascii(34)+'/bin/grep'+ascii(34)+', cmdargc); /* Execute another program*/'
+i=i+1;f(i)=' printf('+ascii(34)+'execv error\n'+ascii(34)+');'
+i=i+1;f(i)='}'
+n=i;
+
+
+
+printf("\n\n$ cat execv.c # to open the file emp.lst")
+halt(' ')
+u=mopen('execv.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 execv.c")
+ halt(' ')
+ printf("$ a.out ")
+ halt(' ')
+ printf("15:sumit:x:102:10::/users1/home/staff/sumit:/usr/bin/bash")
+ 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.7/Result7.txt b/1088/CH24/EX24.7/Result7.txt
new file mode 100755
index 000000000..7c5c4bc16
--- /dev/null
+++ b/1088/CH24/EX24.7/Result7.txt
@@ -0,0 +1,72 @@
+ ans =
+
+ 1.
+
+-->exec('Example7.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 7 : Show the effect of using the execv series
+
+ ****************************************************************
+
+ 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 execv.c # to open the file emp.lst /* Program: execv.c -- Stuffs all command line arguments to an an array to be used with execv */
+
+#include <stdio.h>
+int main(int argc, char **argv) {
+ char *cmdargs[] = { "grep", "-i", "-n", "SUMIT", "/etc/passwd", NULL };
+ execv("/bin/grep", cmdargc); /* Execute another program*/
+ printf("execv error\n");
+}
+ $ cc execv.c $ a.out 15:sumit:x:102:10::/users1/home/staff/sumit:/usr/bin/bash
+
+
+$ 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)
diff --git a/1088/CH24/EX24.8/Example8.sce b/1088/CH24/EX24.8/Example8.sce
new file mode 100755
index 000000000..4e8eb6dd2
--- /dev/null
+++ b/1088/CH24/EX24.8/Example8.sce
@@ -0,0 +1,72 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 8 : Show the effect of using the exec command to run a unix command \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: exec_and_fork.c -- Uses fork, exec and wait to run a unix command */'
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='#include <wait.h>'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(int argc,char **argv) {'
+i=i+1;f(i)=' int returnval; /* Used by wait*/'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' switch(fork()) {'
+i=i+1;f(i)=' case 0: /* Run command in child */'
+i=i+1;f(i)=' if ((exec(argv[1], &argv[2]) < 0 )) {'
+i=i+1;f(i)=' fprintf(stderr, '+ascii(34)+'execl error\n'+ascii(34)+');'
+i=i+1;f(i)=' exit(200);'
+i=i+1;f(i)=' }'
+i=i+1;f(i)=' default: /* In the parent */'
+i=i+1;f(i)=' wait(&returnval); /* After the command has completed .. */'
+i=i+1;f(i)=' fprintf(stderr,'+ascii(34)+'Exit status: %d\n'+ascii(34)+',WEXITSTATUS(returnval));'
+i=i+1;f(i)=' exit(0);'
+i=i+1;f(i)=' }'
+i=i+1;f(i)='}'
+n=i
+
+
+
+printf("\n\n$ cat exec_and_fork.c # to open the file emp.lst")
+halt(' ')
+u=mopen('exec_and_fork.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 exec_and_fork.c")
+ halt(' ')
+ printf("$ a.out /bin/grep grep -i -n SUMIT /etc/passwd ")
+ halt(' ')
+ printf("15:sumit:x:102:10::/users1/home/staff/sumit:/usr/bin/bash\nExit status: 0")
+ 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.8/Result8.txt b/1088/CH24/EX24.8/Result8.txt
new file mode 100755
index 000000000..f2bbe3421
--- /dev/null
+++ b/1088/CH24/EX24.8/Result8.txt
@@ -0,0 +1,84 @@
+ ans =
+
+ 1.
+
+-->exec('Example8.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 8 : Show the effect of using the exec command to run a unix command
+
+ ****************************************************************
+
+ 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 exec_and_fork.c # to open the file emp.lst /* Program: exec_and_fork.c -- Uses fork, exec and wait to run a unix command */
+#include <stdio.h>
+#include <wait.h>
+
+int main(int argc,char **argv) {
+ int returnval; /* Used by wait*/
+
+ switch(fork()) {
+ case 0: /* Run command in child */
+ if ((exec(argv[1], &argv[2]) < 0 )) {
+ fprintf(stderr, "execl error\n");
+ exit(200);
+ }
+ default: /* In the parent */
+ wait(&returnval); /* After the command has completed .. */
+ fprintf(stderr,"Exit status: %d\n",WEXITSTATUS(returnval));
+ exit(0);
+ }
+}
+ $ cc exec_and_fork.c $ a.out /bin/grep grep -i -n SUMIT /etc/passwd 15:sumit:x:102:10::/users1/home/staff/sumit:/usr/bin/bash
+Exit status: 0
+
+
+$ 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)
diff --git a/1088/CH24/EX24.9/Example9.sce b/1088/CH24/EX24.9/Example9.sce
new file mode 100755
index 000000000..38effb613
--- /dev/null
+++ b/1088/CH24/EX24.9/Example9.sce
@@ -0,0 +1,118 @@
+clear
+flag=1
+mode(-1)
+clc
+
+printf("Example 9 : Show the effect of creating a mock child shell which accepts and executes commands \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: shell.c -- Accepts user input as a command to be executed. Users the strtok library function for parsing command line*/'
+i=i+1;f(i)='#include <stdio.h>'
+i=i+1;f(i)='#include <unistd.h>'
+i=i+1;f(i)='#include <string.h> /*for strtok*/'
+i=i+1;f(i)='#include <wait.h>'
+i=i+1;f(i)=''
+i=i+1;f(i)='#define BUFSIZE 200 /*Maximum size for the command line */'
+i=i+1;f(i)='#define ARGVSIZE 40 /* Maximum number of arguments*/'
+i=i+1;f(i)='#define DELIM '+ascii(34)+'\n\t\r'+ascii(34)+' /* White-space delimiters for strtok */'
+i=i+1;f(i)=''
+i=i+1;f(i)='int main(int argc, char **argv) {'
+i=i+1;f(i)=' int i,n ;'
+i=i+1;f(i)=' char buf[BUFSIZE + 1]; /* Stores the entered command line */'
+i=i+1;f(i)=' char *clargs[ARGVSIZE]; /* Stores the arguments strings */'
+i=i+1;f(i)=' int returnval ; /* Used by wait */'
+i=i+1;f(i)=' for (;;) { /* Loop forever */'
+i=i+1;f(i)=' n = 1;'
+i=i+1;f(i)=' write(STDOUT_FILENO, '+ascii(34)+'Shell> '+ascii(34)+',7); /*Display a prompt */'
+i=i+1;f(i)=' read(STDIN_FILENO, buf, BUFSIZE); /* Read user input into buf */'
+i=i+1;f(i)=' if (!strcmp(buf, '+ascii(34)+'exit\n'+ascii(34)+'))'
+i=i+1;f(i)=' exit(0); /* Terminate if user enters exit */'
+i=i+1;f(i)=' /* Now parse buf to extract the */'
+i=i+1;f(i)=' clargs[0] = strtok(buf, DELIM); /* first word */'
+i=i+1;f(i)=' /* Continue parsing until ... */'
+i=i+1;f(i)=' while ((clargs[n] = strtok(NULL, DELIM) != NULL)'
+i=i+1;f(i)=' n++; /* ...all words are extracted */'
+i=i+1;f(i)=' '
+i=i+1;f(i)=' clargs[n] = NULL; /* Set last arguments pointer to NULL */'
+i=i+1;f(i)=' switch(fork()) {'
+i=i+1;f(i)=' case 0:'
+i=i+1;f(i)=' if ((execvp(clargs[0], &clargs[0])) < 0)'
+i=i+1;f(i)=' exit(200); /* We will check this value later */'
+i=i+1;f(i)=' default: /* Int the parent */'
+i=i+1;f(i)=' wait(&returnval); /*After the command has completed.. */'
+i=i+1;f(i)=' printf('+ascii(34)+'Exit status of command: %d\n'+ascii(34)+',WEXITSTATUS(returnval));'
+i=i+1;f(i)=' for (i=0; i<=n ;i++) /*...initialise both... */'
+i=i+1;f(i)=' clargs[i] = '+ascii(34)+'\0'+ascii(34)+'; /*the argument array ...*/'
+i=i+1;f(i)=' for (i=0; i<BUFSIZE+1; i++)'
+i=i+1;f(i)=' buf[i] = '+ascii(39)+'\0'+ascii(39)+'; /* ... and the buffer that stores command */'
+i=i+1;f(i)=' } /* line, so next command can work with */'
+i=i+1;f(i)=' } /* an initialized buffer and argument */'
+i=i+1;f(i)='} /* array */'
+i=i+1;f(i)=''
+n=i
+
+
+
+printf("\n\n$ cat shell.c # to open the file emp.lst")
+halt(' ')
+u=mopen('shell.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 shell.c")
+ halt(' ')
+ printf("$ a.out ")
+ halt(' ')
+ printf("Shell> ")
+ sleep(1500)
+ printf("grep joker /etc/passwd")
+ halt(' ')
+ printf("Exit status of command: 1 #grep returns 1 if pattern not found")
+ halt(' ')
+ printf("Shell> ")
+ sleep(1500)
+ printf("pwd #Is this the shell builtin? ")
+halt(' ')
+printf("/users1/home/staff/sumit\nExit status of command: 0")
+ halt(' ')
+ printf("Shell> ")
+sleep(1500)
+printf("ls -lu /usr/bin/pwd # Now check the access time of on-disk pwd")
+halt(' ')
+printf("-r-xr-xr-x 1 root bin 4360 May 29 01:33 /use/bin/pwd\nExit status of command: 0 # Disk file has just been accessed! ")
+ halt(' ')
+ printf("Shell> ")
+sleep(1500)
+printf("exit")
+halt('')
+printf("$_ # Back to parent shell")
+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.9/Result9.txt b/1088/CH24/EX24.9/Result9.txt
new file mode 100755
index 000000000..b1eba0ff0
--- /dev/null
+++ b/1088/CH24/EX24.9/Result9.txt
@@ -0,0 +1,109 @@
+ ans =
+
+ 1.
+
+-->exec('Example9.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 9 : Show the effect of creating a mock child shell which accepts and executes commands
+
+ ****************************************************************
+
+ 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 shell.c # to open the file emp.lst /* Program: shell.c -- Accepts user input as a command to be executed. Users the strtok library function for parsing command line*/
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h> /*for strtok*/
+#include <wait.h>
+
+#define BUFSIZE 200 /*Maximum size for the command line */
+#define ARGVSIZE 40 /* Maximum number of arguments*/
+#define DELIM "\n\t\r" /* White-space delimiters for strtok */
+
+int main(int argc, char **argv) {
+ int i,n ;
+ char buf[BUFSIZE + 1]; /* Stores the entered command line */
+ char *clargs[ARGVSIZE]; /* Stores the arguments strings */
+ int returnval ; /* Used by wait */
+ for (;;) { /* Loop forever */
+ n = 1;
+ write(STDOUT_FILENO, "Shell> ",7); /*Display a prompt */
+ read(STDIN_FILENO, buf, BUFSIZE); /* Read user input into buf */
+ if (!strcmp(buf, "exit\n"))
+ exit(0); /* Terminate if user enters exit */
+ /* Now parse buf to extract the */
+ clargs[0] = strtok(buf, DELIM); /* first word */
+ /* Continue parsing until ... */
+ while ((clargs[n] = strtok(NULL, DELIM) != NULL)
+ n++; /* ...all words are extracted */
+
+ clargs[n] = NULL; /* Set last arguments pointer to NULL */
+ switch(fork()) {
+ case 0:
+ if ((execvp(clargs[0], &clargs[0])) < 0)
+ exit(200); /* We will check this value later */
+ default: /* Int the parent */
+ wait(&returnval); /*After the command has completed.. */
+ printf("Exit status of command: %d\n",WEXITSTATUS(returnval));
+ for (i=0; i<=n ;i++) /*...initialise both... */
+ clargs[i] = "\0"; /*the argument array ...*/
+ for (i=0; i<BUFSIZE+1; i++)
+ buf[i] = '\0'; /* ... and the buffer that stores command */
+ } /* line, so next command can work with */
+ } /* an initialized buffer and argument */
+} /* array */
+
+ $ cc shell.c $ a.out Shell> grep joker /etc/passwd Exit status of command: 1 #grep returns 1 if pattern not found Shell> pwd #Is this the shell builtin? /users1/home/staff/sumit
+Exit status of command: 0 Shell> ls -lu /usr/bin/pwd # Now check the access time of on-disk pwd -r-xr-xr-x 1 root bin 4360 May 29 01:33 /use/bin/pwd
+Exit status of command: 0 # Disk file has just been accessed! Shell> exit$_ # Back to parent shell
+
+
+$ 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)