09 - Chapter 05 - Q4 if(argc > 4 argv[3 argv[1 argv[2 argv[0 printf\"Too many arguments\\n prog-f in out exit(1 prog-s in else if(argc < 3 printf\"Not

09 - Chapter 05 - Q4 if(argc > 4 argv[3 argv[1 argv[2...

This preview shows page 1 - 10 out of 33 pages.

Q4: if(argc > 4) { printf("Too many arguments\n"); exit(1); } else if(argc < 3) { printf("Not enough arguments\n"); exit(1); } else //valid command line { countWords; //see the C program example in Unix Tutorial if(argc == 4 && strcmp(argv[1], "-f") == 0) { outfile = fopen(argv[3],"w"); fprintf(outfile, "%d characters\n", char_count); fclose(outfile); } else if (argc == 3 && strcmp(argv[1], "-s") == 0) printf("%d characters.\n", char_count); } UHD_CS4315 1 prog -f in.txt out.txt prog -s in.txt argv[0] argv[1] argv[2] argv[3]
2 Chapter 5 Process Synchronization UHD_CS4315
Background Processes can execute concurrently Concurrent access to shared data may result in data inconsistency OS must provide mechanisms to ensure the orderly execution of cooperating processes Illustration of the problem: producer-consumer 3 UHD_CS4315