1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
cupoosta [38]
3 years ago
6

Please use thread to complete the following program: one process opens a file data.txt, then creates a thread my_thread. The job

of the thread my_thread is to count how many lines exist in the file data.txt, and return the number of lines to the calling process. The process then prints this number to the screen.
Basically, you need to implement main_process.c and thread_function.c.
Basic structure of main_process.c:
int main ()
{
Open the file data.txt and obtain the file handler fh;
Create a thread my_thread using pthread_create; pass fh to my_thread;
Wait until my_thread terminates, using pthread_join;
Print out how many lines exist in data.txt.}
Basic structure of thread_function.c:
void *count_lines(void *arg)
{
Obtain fh from arg;
Count how many lines num_lines exist in fh;
Close fh;
Return num_lines
}
Computers and Technology
1 answer:
Firlakuza [10]3 years ago
8 0

Answer:

Here is the code:-

//include the required header files

#include<stdio.h>

#include<pthread.h>

// method protocol definition

void *count_lines(void *arg);

int main()

{

    // Create a thread handler

    pthread_t my_thread;

    // Create a file handler

    FILE *fh;

    // declare the variable

    int *linecnt;

    // open the data file

    fh=fopen("data.txt","r");

// Create a thread using pthread_create; pass fh to my_thread;

    pthread_create(&my_thread, NULL, count_lines, (void*)fh);

    //Use pthread_join to terminate the thread my_thread

    pthread_join( my_thread, (void**)&linecnt );

    // print the number of lines

printf("\nNumber of lines in the given file: %d \n\n", linecnt);

    return (0);

}

// Method to count the number of lines

void *count_lines(void *arg)

{

    // variable declaration and initialization

    int linecnt=-1;

    char TTline[1600];

    //code to count the number of lines

    while(!feof(arg))

    {

         fgets(TTline,1600,arg);

         linecnt++;

    }

    pthread_exit((void *)linecnt);

    // close the file handler

    fclose(arg);

}

Explanation:

Program:-

You might be interested in
________ refers to the ICT architecture, where users access software applications and information systems remotely over the Inte
Slav-nsk [51]

Answer:

Cloud computing

Explanation:

Cloud computing refers to the process of making computer system resources like computing power and data storage available to user on-demand without requiring the user to manage them himself. The computer system resources include servers, applications, networks, services, storage, and others.

It allows data center to be available over the internet to a large number of users.

Cloud computing involves employing a network of remote servers which are hosted on the Internet for processing, storing, and managing data, instead of using a personal computer or a domestic server. Its aim is to ensure a coherence and economies of scaled through resources sharing.

There are two types of cloud computing: enterprise clouds, which its use can be restricted to just one organisation; and public cloud, which is meant for many organisation.

3 0
3 years ago
Which is a safe practice when online
Kay [80]

Answer:

I don't know if there are choices but these are couple that i think would be right. Don't give out personal info, have a complex password and don't give it out to anyone, don't click on random pop up adds, and use a firewall

Explanation:

7 0
3 years ago
Read 2 more answers
Regarding the Internet of Things (IoT), a business involved in utilities, critical infrastructure, or environmental services can
jeka94

Answer:

A. true

Explanation:

Based on the information provided within the question it can be said that the statement is completely true. This is because, traffic-monitoring applications have the main function of monitoring and analyzing the flow of traffic of one or various different items. Which can be applied to the business involving utility, infrastructure, and environmental services by monitoring the specific items regarding each business. Therefore making sure that enough product is entering or leaving each business as it is suppose to. As well as providing stock analysis and defective product alerts.

6 0
4 years ago
Size of a request header field exceeds server limit.
garri49 [273]
Try to Increase the value for the directive LimitRequestFieldSize in the httpd.conf:


Reason: This is normally caused by having a very large Cookie, so a request header field exceeded the limit set for Web Server.
For IBM® HTTP Server, this limit is set by LimitRequestFieldSize directive (default 8K). The LimitRequestFieldSize directive allows the Web server administrator to reduce or increase the limit on the allowed size of an HTTP request header field.
SPNEGO authentication headers can be up to 12392 bytes. This directive gives the server administrator greater control over abnormal client request behavior, which may be useful for avoiding some forms of denial-of-service attacks.

8 0
3 years ago
2- There are many different design parameters that are important to a cache’s overall performance. Below are listed parameters f
katen-ka-za [31]

Answer:

1. 2588672 bits

2. 4308992 bits

3. The larger the data size of the cache, the larger the area of ​​memory you will need to "search" making the access time and performance slower than the a cache with a smaller data size.

Explanation:

1. Number of bits in the first cache

Using the formula: (2^index bits) * (valid bits + tag bits + (data bits * 2^offset bits))

total bits = 2^15 (1+14+(32*2^1)) = 2588672 bits

2. Number of bits in the Cache with 16 word blocks

Using the formula: (2^index bits) * (valid bits + tag bits + (data bits * 2^offset bits))

total bits = 2^13(1 +13+(32*2^4)) = 4308992 bits

3. Caches are used to help achieve good performance with slow main memories. However, due to architectural limitations of cache, larger data size of cache are not as effective than the smaller data size. A larger cache will have a lower miss rate and a higher delay. The larger the data size of the cache, the larger the area of ​​memory you will need to "search" making the access time and performance slower than the a cache with a smaller data size.

5 0
3 years ago
Other questions:
  • The inventory tracking system shows that 12 laptop were on hand before a customer brings two laptops to the register for purchas
    9·1 answer
  • Nina is explaining the SQA process to her friend Amanda.
    9·1 answer
  • Once I have entered text into a presentation, how do I modify the font style of the text? Select the text and use options availa
    9·2 answers
  • Users report that the network access is slow. After questioning the employees, the network administrator learned that one employ
    10·1 answer
  • Difference between switch case and if else statement.​
    11·1 answer
  • The Matlab Script should:1. Clear the command window2. Clear the workspaceQuestion 1: Why do we clear the command window and wor
    9·1 answer
  • Which of the following is considered a skill?
    11·1 answer
  • How do even do anything on Rblx Creator?? Will give branliest for whoever gives me the most info.
    13·1 answer
  • "Automated Deployment" is one of the prerequisite for DevOps implementation.
    8·1 answer
  • You have a server with two physical processors, each with four cores for a total of 8 cores. How many license packs must you buy
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!