Question

In: Computer Science

(learning about sockets) can I have an example of how to use child threads in a...

(learning about sockets) can I have an example of how to use child threads in a client.cpp to send info to a server.cpp. and how a server.cpp uses child processes to send back info to the client

Solutions

Expert Solution

Here is the example of how to use child threads in a client.cpp to send info to a server.cpp and how a server.cpp uses child processes to send back info to the client.

 #include <unistd.h> #include <stdlib.h> #include <sys/wait.h> #include <stdio.h> int main() { int status; pid_t pid = fork(); // Child process will sleep for 10 second if(pid == 0) { execl("/usr/bin/sleep", "/usr/bin/sleep", 10, NULL); } // Parent process will wait for child process to terminate // Then, it will report the exit status of the child process else { waitpid(pid, &status;, 0); printf("status = %d\n", status); // print out -> status = 65280 } }

Here are the some keyword used in the program which have meanings as follows like..

1. Execl() -- It is used here for to execute the sleep program.

2. Waitpid()-- It is used here for wait for state changes in a child of the calling process, and obtain information about the child whose state has changed. A state change is considered to be:

  1. the child terminated
  2. the child was stopped by a signal
  3. the child was resumed by a signal

In the case of a terminated child, performing a wait allows the system to release the resources associated with the child.
If a wait  is not performed, then the terminated child remains in a zombie state.

If a child has already changed state, then it returns immediately. Otherwise it block until either a child changes state or a signal handler interrupts the call.


Related Solutions

Please write a short essay on How can I use operant conditioning (learning theory) as a...
Please write a short essay on How can I use operant conditioning (learning theory) as a parent to modify my kid's behavior
How can I convert inRange in cv2 to PIL? For example, I already have mask =...
How can I convert inRange in cv2 to PIL? For example, I already have mask = cv2.inRange(img, array1, array2) but I'm trying to keep everything in PIL. Any ideas would be appreciated!
How will you make customers read your corporate blog? As an example, I have about 50...
How will you make customers read your corporate blog? As an example, I have about 50 tabs (more, 30 in the phone only) with stuff I wanted to read but never got to it.
This week we have been learning about the methods archaeologists and paleontologists use to reconstruct the...
This week we have been learning about the methods archaeologists and paleontologists use to reconstruct the past. Now it’s time to get creative and apply this new knowledge to the present day. This is going to involve a little bit of research and creativity on your part. Pick a room in your house, apartment, dorm, or alternative domicile. If you walked out the door today and your room remained untouched for 100, 1,000 or 50,000 years, what would be left...
Is learning a type of thinking? I have to do a essay on how technology impacts...
Is learning a type of thinking? I have to do a essay on how technology impacts thinking behavior, and use studies to show proof of reason. However most of the studies I found are in technology and learning and I don't really know if that would be considered thinking. Please help I'm desperate!
Provide an example that demonstrates how Learning Patterns play (or have played) a role in your...
Provide an example that demonstrates how Learning Patterns play (or have played) a role in your interactions with the person you selected. Consider which Learning Pattern(s) help you connect and work positively with this person and conversely, which Pattern(s) have contributed to or have the potential to lead to Pattern Conflict.
Learning and Development Foundation: -Developmental Suggestion for 18 months talk about the development of the child?...
Learning and Development Foundation: -Developmental Suggestion for 18 months talk about the development of the child? and the teachers and parent role? -Socio-Emotional Development -Language Development & Literacy -Number Sense -Physical Development
How can students use judgments of learning to improve the efficiency of their study? What are...
How can students use judgments of learning to improve the efficiency of their study? What are the potential drawbacks of relying on judgments of learning? How have these drawbacks been tested?
You have AU$ 1.000.000 a. What is interest arbitrage? b. Use example and explain how can...
You have AU$ 1.000.000 a. What is interest arbitrage? b. Use example and explain how can you make profit using interest arbitrage. c. Outline various market conditions where making profit is impossible. (Explain why interest parity hold in long run)
Learning: Operant Conditioning Psychologists like B. F. Skinner have studied how we can use operant conditioning...
Learning: Operant Conditioning Psychologists like B. F. Skinner have studied how we can use operant conditioning to change the behavior of people and animals. Drawing on your personal experience, choose a person or animal whose behavior you want to change. (You may select your own behavior for this question if you wish.) How could you use operant conditioning to change the behavior of this person or animal? In a multi-paragraph essay, describe your plan to change this behavior. Be sure...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT