3000pc.c 3000random.c QUESTIONS!!!! 1.[1] Why does a different version of stat()
ID: 3601151 • Letter: 3
Question
3000pc.c
3000random.c
QUESTIONS!!!!
1.[1] Why does a different version of stat(), lstat(), exist that treats symbolic links differently? Why isn't a different version needed for hard links?
2. [1] How can you modify 3000pc so the producer stops producing once it fills the queue?
3.[1] Under what circumstances is fill_rand_buffer() called in 3000random?
4.[1] If the two signal handling functions in 3000pc were replaced by one function, would there be any significant loss of functionality? Briefly explain.
5. [2] How could you modify 3000test.c so it can report on whether two device files are equal without actually accessing the underlying devices? Specify the changes you would make to 3000test.c rather than doing this from scratch.
6.[2] Does the MAP_SHARED flag on line 60 of 3000test.c (inside the call to mmap) make a significant difference in its execution? Specifically, what happens when you remove it or changed it to MAP_PRIVATE? Why?
7. [2] When a file is mmap'd into memory, when is its contents loaded from disk? How can you verify this using 3000test?
8. [2] What is one way simple way you can modify 3000pc so the consumer consumes as the producer produces, i.e., the producer and the consumer move essentially in lock step? Your modification should not involve sleeping by either the producer or the consumer. Why does your change work? (To do this precisely is hard; to do this approximately involves a change to one line. The approximate solution is sufficient.)
9. [2] Which is faster, /dev/urandom or /dev/random? What evidence do you have for this difference based on code that you ran (3000random or other programs)?
10. [2] How does the behavior of 3000pc change if you delete lines 149 and 152 (the if statement in wakeup_consumer())? Why? (Explain what the program does after this change and why it may be problematic.)
11. [2] What happens if you delete line 231 (the call to wakeup_producer()) in 3000pc? Why?
12. [2] How does the behavior of the program change if you change QUEUESIZE to 8? What about 128?
3000pc.c
3000random.c
Questions!!!
11 VIRGIN 1:28 PM homeostasis.scs.carleton.ca Code /2 et. 1, 2027 Licenced onder the GPLw, copyright And Sonayaj You really shoud be neorporating parts of it is meant for teaching not productlon inelude c stdlib "·ineludeExplanation / Answer
1)A "hard link" is actually between two directory entries; they're really the same file.
Every directory is itself a file, only special because it contains a list of file names maintained by the file system. Since directories themselves are files, multiple hard links to directoriesare possible which would create loops within the structure of the directories, rather than a branching structure like a tree. For that reason, the creation of hard links to directories is sometimes forbidden, even if possible.BASED ON THE DEPENDANCIES WE CAN USE THE STAT OR ISTAT
2)public static class PC
{
// Create a list shared by producer and consumer
// Size of list is 2.
LinkedList<Integer> list = new LinkedList<>();
int capacity = 2;
// Function called by producer thread
public void produce() throws InterruptedException
{
int value = 0;
while (true)
{
synchronized (this)
{
// producer thread waits while list
// is full
while (list.size()==capacity)
wait();
System.out.println("Producer produced-"
+ value);
// to insert the jobs in the list
list.add(value++);
// notifies the consumer thread that
// now it can start consuming
notify();
// makes the working of program easier
// to understand
Thread.sleep(1000);
}
}
}
3)void is a return type and r used to write the values at the particular line of queue and where as the values are being compressed by the buffer,It is included to avoid any confusion.
4)HERE TWO LINKS WERE SPECIFIED.OBVIOUSLY THERE WILL BE LOSS IN FUNCTIONALITY.AS SAId above if a tree with no branches just imagine.
5)THE CHANGES CANNOT BE SPECIFIED WITHOU ACCESSING THE UNDERLYING DEVICES
6)EITHER ONE IS TO BE SPECIFIED BUT NOT BOTH
7)
A process creates a shared memory segment using shmget()|. The original owner of a shared memory segment can assign ownership to another user with shmctl(). It can also revoke this assignment. Other processes with proper permission can perform various control functions on the shared memory segment using shmctl(). Once created, a shared segment can be attached to a process address space using shmat(). It can be detached using shmdt() (see shmop()). The attaching process must have the appropriate permissions for shmat(). Once attached, the process can read or write to the segment, as allowed by the permission requested in the attach operation. A shared segment can be attached multiple times by the same process. A shared memory segment is described by a control structure with a unique ID that points to an area of physical memory. The identifier of the segment is called the shmid. The structure definition for the shared memory segment control structures and prototypews can be found in <sys/shm.h>.IN SOLARIS 2x oper.ating system
8)public void consume() throws InterruptedException
{
while (true)
{
synchronized (this)
{
// consumer thread waits while list
// is empty
while (list.size()==0)
wait();
//to retrive the ifrst job in the list
int val = list.removeFirst();
System.out.println("Consumer consumed-"
+ val);
// Wake up producer thread
notify();
// and sleep
Thread.sleep(1000);
}
}
}
}
}
9)Generating good randomness takes time. ... /dev/random uses a lot of system entropy, and so produces only a slow data stream. /dev/urandom is less secure, and faster, but it's still geared towards smaller chunks of data - it's not meant to provide a continuous stream of high speed random numbers.
10)SOME THREADS WILL BE ACTIVE.
11)PRODUCER THREADS WILL BE ACTIVE AND START PRODUCING THE CONTENT
12)EIGHT SLOTS WILL BE CREATED SATRTING FROM 0-7.THE SAME CASE HAPPENS IN 128
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.