Sponsored Content
Full Discussion: Help with C programming
Top Forums Programming Help with C programming Post 302512853 by omega666 on Monday 11th of April 2011 05:42:48 PM
Old 04-11-2011
Power Help with C programming

for a question like this

Assume you have a server with two clients and two child processes. The server retrieves data from the
children through a pipe (one each) and writes data to the clients through a socket (one each). child1
produces data for client1, and child2 for client2.
Write a C loop that performs the above actions, making sure that at no time will the server sit and wait
for data from one child when the other child has data to pass. If either child dies, exit the loop.
You need to write only the loop transferring the data. Assume that all connections to pipes and sockets
have been established, and no more clients will try to connect to this server.
The pipes are declared in arrays p1 and p2, respectively. The sockets are s1, and s2.
You may use this function (you do not have to write it):
int transfer(int p, int s)
which gets data from pipe p and puts it into socket s, and returns the number of bytes read from the pipe.
is this correct?
Code:
while(1) {
    rset = allset;
    nready = select(maxfd+1, &rset, NULL, NULL, NULL);
    if (nready < 0) {
        perror("ERROR select error");
    }
    else if (FD_ISSET(p1[0], &rset)) {
        if ((bytes = transfer(p1[0], s1)) < 0) {
            perror("ERROR read error");
        }
        else if (bytes==0) {
            break;
        }
    }
    else if (FD_ISSET(p2[0], &rset)) {
        if ((bytes = transfer(p2[0], s2)) < 0) {
            perror("ERROR read error");
        }
        else if (bytes==0) {
            break;
        }
    }
}

 

10 More Discussions You Might Find Interesting

1. Programming

c programming on vi

i am new in linux environment .I have used vi editor of Unix to get a programe compiled through "gcc ".kindly give me the options to get a program compiled & executed written in c on vi editor. I want the command to compile a file and the command to get that compiled file executed with any... (2 Replies)
Discussion started by: Rajraius
2 Replies

2. Programming

c programming or unix programming!?

i would like advice on the usbject of c programming (in the middle of reading a book on C). could i benefit more if i apply that knowledge in the unix format if i were able to, or would that take the point out of learning C, basically I want to stay away from strying too far away from unix and use... (1 Reply)
Discussion started by: moxxx68
1 Replies

3. Shell Programming and Scripting

Unix Systems Programming Vs Unix Programming

Several months ago I found a link that explained the difference between how a Unix Systems Admin would do scripting compared to what a Unix Programmer would do. It showed a basic script and then show several iterations that explained how the Systems Admin would change it to make it better. I was... (0 Replies)
Discussion started by: BCarlson
0 Replies

4. Programming

C++ programming

Sorry to ask this question here... where can I find a C++ programming thread? Thanks guys! (7 Replies)
Discussion started by: nadiamihu
7 Replies

5. Shell Programming and Scripting

New To Programming

Hello all!! I am new to programming, and to this forum. :D I am having sort of a problem. Me and my coworker are working on a code, both of us are stumped on a few things. One is we have a whole log file, i have found how to extract by column, but not by row. I need to extract by both.:confused:... (7 Replies)
Discussion started by: xkayla06
7 Replies

6. UNIX for Dummies Questions & Answers

Carreer:Networking Programming in Unix (C programming Language)

Hello, I am trying to learn Networking Programming in C in unix enviorment. I want to know how good it is to become a network programmer. i am crazy about Network programming but i also want to opt for the best carreer options. Anybody experienced Network Programmer, please tell me is my... (5 Replies)
Discussion started by: vibhory2j
5 Replies

7. Programming

C Programming - Hardware Programming

Can someone help me on suggesting some ways to access the memory content in RAM directly from C/C++ source code. Please provide me any book name or any URL so that I can get an exhaustive knowledge over it. If possible please give me some tips on interacting with hardwares directly through... (3 Replies)
Discussion started by: nandumishra
3 Replies

8. Shell Programming and Scripting

Sh programming

I have started writing one script. It is not taking the if block. Here is the script: #!/bin/sh set USER='/usr/ucb/whoami' ####################################################################### #Killing Process #######################################################################... (6 Replies)
Discussion started by: amarpreetka
6 Replies

9. UNIX for Dummies Questions & Answers

How does unix system administration, unix programming, unix network programming differ?

How does unix system administration, unix programming, unix network programming differ? Please help. (0 Replies)
Discussion started by: thulasidharan2k
0 Replies

10. UNIX for Dummies Questions & Answers

From iOS programming to Linux system programming

Hello. I like Linux and C programming language. Allways wanted to understand kernel and become a Linux system programmer. And I also like Objective-C and iOS. These two programming areas have relations: 1. Linux and iOS are UNIX-like systems, POSIX compliant. 2. It is useful to know C language... (2 Replies)
Discussion started by: Rockatansky
2 Replies
Net::Server::Fork(3)					User Contributed Perl Documentation				      Net::Server::Fork(3)

NAME
Net::Server::Fork - Net::Server personality SYNOPSIS
use base qw(Net::Server::Fork); sub process_request { #...code... } __PACKAGE__->run(); DESCRIPTION
Please read the pod on Net::Server first. This module is a personality, or extension, or sub class, of the Net::Server module. This personality binds to one or more ports and then waits for a client connection. When a connection is received, the server forks a child. The child handles the request and then closes. With the exception of parent/child signaling, this module will work (with basic functionality) on Win32 systems. ARGUMENTS
check_for_dead Number of seconds to wait before looking for dead children. This only takes place if the maximum number of child processes (max_servers) has been reached. Default is 60 seconds. max_servers The maximum number of children to fork. The server will not accept connections until there are free children. Default is 256 children. max_dequeue The maximum number of dequeue processes to start. If a value of zero or undef is given, no dequeue processes will be started. The number of running dequeue processes will be checked by the check_for_dead variable. check_for_dequeue Seconds to wait before forking off a dequeue process. It is intended to use the dequeue process to take care of items such as mail queues. If a value of undef is given, no dequeue processes will be started. CONFIGURATION FILE
See Net::Server. PROCESS FLOW
Process flow follows Net::Server until the post_accept phase. At this point a child is forked. The parent is immediately able to wait for another request. The child handles the request and then exits. HOOKS
The Fork server has the following hooks in addition to the hooks provided by the Net::Server base class. See Net::Server "$self->pre_accept_hook()" This hook occurs just before the accept is called. "$self->post_accept_hook()" This hook occurs in the child after the accept and fork. "$self->run_dequeue()" This hook only gets called in conjunction with the check_for_dequeue setting. HOT DEPLOY
Since version 2.000, the Fork server has accepted the TTIN and TTOU signals. When a TTIN is received, the max_servers is increased by 1. If a TTOU signal is received the max_servers is decreased by 1. This allows for adjusting the number of handling processes without having to restart the server. AUTHOR
Paul Seamons <paul@seamons.com> Rob Brown <bbb@cpan.org> SEE ALSO
Please see also Net::Server::INET, Net::Server::PreFork, Net::Server::MultiType, Net::Server::SIG Net::Server::Single perl v5.18.2 2013-01-09 Net::Server::Fork(3)
All times are GMT -4. The time now is 04:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy