473,385 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

tcp and fork


hallo there,

Can anyone help me to look at my fork problems? I can't seem to
work up the piping..the reason i need that for is because i need to
make a counter global to client and server.(once fork start,
counter will reset). This allow me to communicate with my
counter.....pls help and thanks a lot

sim













for ( ; ; ) {

if ( ((connfd=Accept(listenfd, (SA *) &cliaddr,
&clilen)) < 0)&&(myclients[2].pid=0)){

if (errno == EINTR){

continue;

}

else

err_sys("accept error");

}

else if (myclients[2].pid>0)

{

err_quit("Max client");

}

curtime = time (NULL);

loctime = localtime (&curtime);

client_date = asctime (loctime);

//Check The IP and PORT number here//

if(getpeername(connfd, (struct sockaddr *) &cliaddr,
&clilen)>=0)

{

gethostname( hname, sizeof(hname) );

p = gethostbyname( hname );

for (f = 0; p->h_addr_list[f]; ++f) {

(struct in_addr *)ip = p-
h_addr_list[f];


user_ip = p->h_name;

myclients[max_client].ip =
inet_ntoa(cliaddr.sin_addr);

myclients[max_client].port =
ntohs(cliaddr.sin_port);

myclients[max_client].time = client_date;

myclients[max_client].start = curtime;

}

myclients[max_client].pid = getpid();

//printf("client number %d has pid %d \n", max_client, getpid());
//printf("client number %d has ip %s and port %d\n", max_client,
myclients[max_client].ip, myclients[max_client].port);

//printf("client pid number %d has pid: %d ip %s
port %d time %s duration \n", max_client,
myclients[max_client].pid,
myclients[max_client].ip, myclients[max_client]-
.port,myclients[max_client].time,myclients[max_-
client].duration);

}

pipe(pipe1);

childpid = Fork();

max_client++;

if ((childpid == 0)) { // child process //

Close(pipe1[1]); // close listening
socket //

clilen = sizeof(cliaddr); // process
the request

printf("socket is %d\n", connfd);

printf("pipe1[0] is %d and pipe1[1] is
%d\n", pipe1[0], pipe1[1]);

****This is the function where i neeed to
use pipe for

str_echo(connfd,cliaddr,clilen,childpid-
,&mycounter,pipe1[0],pipe1[1],max_clien-
t,wait_time,myclients);

}

else if (childpid >0)

{

Close(pipe1[1]); // parent
closes connected socket //

}

}

}
--
Posted via http://dbforums.com
Nov 13 '05 #1
4 2874
marconi <me*********@dbforums.com> scribbled the following:
hallo there,
Can anyone help me to look at my fork problems? I can't seem to
work up the piping..the reason i need that for is because i need to
make a counter global to client and server.(once fork start,
counter will reset). This allow me to communicate with my
counter.....pls help and thanks a lot


Your code depends way too much on non-standard extensions to C to be
topical here. Please ask on comp.unix.programmer instead. Thanks.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"My absolute aspect is probably..."
- Mato Valtonen
Nov 13 '05 #2
On Tue, 09 Sep 2003 01:59:04 -0400
marconi <me*********@dbforums.com> wrote:

hallo there,

Can anyone help me to look at my fork problems? I can't seem to
work up the piping..the reason i need that for is because i need to
make a counter global to client and server.(once fork start,
counter will reset). This allow me to communicate with my
counter.....pls help and thanks a lot


Off-topic in c.l.c, comp.unix.programmer.

<snip gadawfully formatted piece of offtopic source code>

Before posting to comp.unix.programmer, reformat it. It's horrible. Use
two-space indentation for example, and get rid of all the excess spaces.

--
char*x(c,k,s)char*k,*s;{if(!k)return*s-36?x(0,0,s+1):s;if(s)if(*s)c=10+(c?(x(
c,k,0),x(c,k+=*s-c,s+1),*k):(x(*s,k,s+1),0));else c=10;printf(&x(~0,0,k)[c-~-
c+"1"[~c<-c]],c);}main(){x(0,"^[kXc6]dn_eaoh$%c","-34*1'.+(,03#;+,)/'///*");}
Nov 13 '05 #3
marconi wrote:

Can anyone help me to look at my fork problems? I can't seem to
work up the piping..the reason i need that for is because i need
to make a counter global to client and server.(once fork start,
counter will reset). This allow me to communicate with my
counter.....pls help and thanks a lot


In a large part of the global world, the fork is held in the left
hand, and the knife in the right. A majority (but definitely not
all) of USAnians reverse this, in that they put down the knife
and transfer the fork to the right hand. The piping is generally
implemented with a straw, and it is customary to tip the server.

Since the C standard has no definitions contrary to the above, my
reply is quite suitable. In other words, you are off topic, and
should look for a newsgroup that deals with your system.
comp.unix.programming and alt.gourmet come to mind.

--
Replies should be to the newsgroup
Chuck Falconer, on vacation.
Nov 13 '05 #4
As others have mentioned, your question is off-topic here;
the folks in comp.unix.programmer can probably help you.

Before you post there, I strongly suggest that you make sure that any
code samples you include are *exactly* the code that you've actually
compiled, preferably a complete, self-contained, short program.

I mention this because you refer to functions "Accept", "Fork", and
"Close". Unix-like systems typically do not provide these functions,
but they do provide functions "accept", "fork", and "close".

--
Keith Thompson (The_Other_Keith) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Benoit Dejean | last post by:
hello, i have a question about forking processes atm, i have some code which i want to rewrite os.system("cd ~ && exec " + cmd + " & disown") i want to remove this os.system call
6
by: shellcode | last post by:
the code: ------fork.c------ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> int main() {
27
by: steve | last post by:
I was given the following code, and asked what the possible outputs could be. We're learning about processes and forking. int value; int main(){ int pid, number = 1; value = 2; pid = fork();...
11
by: ramu | last post by:
Hi All, We know that a c function never returns more than one value. Then how come the fork() function returns two values? How it is implemented? Regards
1
by: vduber6er | last post by:
Hi I want to have a wait page while the rest of the cgi does its process, but it seems like the wait page waits till everything is complete and never appears. I've tried forking twice already as...
3
by: thrillseekersforever | last post by:
The questions(A&B) are to fine no# of process running from the below codes. However, I couldn't decipher the solution. Will someone please throw some light on this? Thanks a lot!! A] void...
5
by: JoeW | last post by:
Now before I go into detail I just want to say that this is purely for my own benefit and has no real world usage. I remember way back when the tool for *nix systems called forkbomb was created. I...
3
by: CMorgan | last post by:
Hi everybody, I am experiencing an annoying problem with fork() and execv(). In my program I need to launch the "pppd" from a thread, so, I create a new process with fork and then in the child...
9
by: Gilles Ganault | last post by:
Hello I need to launch a Python script, and fork it so that the calling script can resume with the next step will the Python script keeps running. I tried those two, but they don't work, as...
2
by: Radz | last post by:
when the fork system call is executed, a new process is created. The original process is called the parent process whereas the new process is called the child process. The new process consists of a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.