homework posted for FLOVODOH
Exercise 4.31.32: (removesubsargs.c) This programming exercise is a modification of Programming Exercise 4.31.30. The command-line arguments expected are the same, and the same errors should be handled in the same manner. The difference is that this program must remove all occurrences of the first string in the second string, and the resulting string and the number of occurrences that were found/removed must be written to standard output. The following are some sample, non-exhaustive test cases. Your program is expected to produce identical output. Do not prompt for input. 1 $ ./a . out hehe xxxheheheyyy −nooverlap 2 1 3 xxxheyyy 4 $ ./a . out hehe xxxheheheyyy 5 2 6 xxxyyy 7 $ ./a . out xx xxxheheheyyy 8 2 9 heheheyyy 10 $ ./a . out yy xxxheheheyyy −nooverlap 11 1 12 xxxhehehey 13 $ ./a . out qq xxxheheheyyy −nooverlap 14 0 15 xxxheheheyyy 16 $ ./a . out qq 17 Usage : string1 string2 [−nooverlap] 18 $ echo $? 19 1 20 $ ./a . out "" "" 21 Search string cannot be empty! 22 $ echo $? 23 1 24 $ ./a . out hello "" 25 0 26 27 $
Keep your program to approximately 50 lines of code.
2.
Write a C (not C++) program which spawns and synchronizes 20 processes to print the following to stderr (of course, with different process and parent process ids): PPID: 310, PID: 497, ping PPID: 497, PID: 498, pong PPID: 498, PID: 499, ping PPID: 499, PID: 500, pong PPID: 500, PID: 501, ping PPID: 501, PID: 502, pong PPID: 502, PID: 503, ping PPID: 503, PID: 504, pong PPID: 504, PID: 505, ping PPID: 505, PID: 506, pong PPID: 506, PID: 507, ping PPID: 507, PID: 508, pong PPID: 508, PID: 509, ping PPID: 509, PID: 510, pong PPID: 510, PID: 511, ping PPID: 511, PID: 512, pong PPID: 512, PID: 513, ping PPID: 513, PID: 514, pong PPID: 514, PID: 515, ping PPID: 515, PID: 516, pong CONFIDENTIAL DRAFT 124 CHAPTER 7. PROCESSES: CREATION, ENVIRONMENT, MANIPULATION, AND COMMUNICATION The first process must print ping to stderr and its child must print pong to stderr, then the child of that child must print ping to stderr and its child must print pong to stderr, and so on. No fancy C library functions or Linux system calls, beyond what has been covered in class, is necessary for this program. Do not use any C constructs not presented in class unless you have discussed their use in your approach with the instructor first. Requirements:
a) Your program must be written in C (not C++) and compile cleanly with gcc.
b) The first process must print ping to stderr and its child must print pong to stderr, then the child of that child must print ping to stderr and its child must print pong to stderr, and so on.
c) Do not use the system call wait in your program because it is unecessary and, of course, sleep cannot be used to synchronize the processes because it does not guarantee the order in which the processes will run.
d) The processes forked need not terminate in reverse order of creation; it is okay if the parent terminates before the child it forked and the command prompt displays between some of the lines of output.
e) Keep your program to approximately 25 lines of code.