473,761 Members | 10,684 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(cliad dr.sin_addr);

myclients[max_client].port =
ntohs(cliaddr.s in_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,pip e1[0],pipe1[1],max_clien-
t,wait_time,myc lients);

}

else if (childpid >0)

{

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

}

}

}
--
Posted via http://dbforums.com
Nov 13 '05 #1
4 2892
marconi <me*********@db forums.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.progr ammer instead. Thanks.

--
/-- Joona Palaste (pa*****@cc.hel sinki.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*********@db forums.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.progr ammer.

<snip gadawfully formatted piece of offtopic source code>

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

--
char*x(c,k,s)ch ar*k,*s;{if(!k) return*s-36?x(0,0,s+1):s ;if(s)if(*s)c=1 0+(c?(x(
c,k,0),x(c,k+=* s-c,s+1),*k):(x(* s,k,s+1),0));el se 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.progr amming 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.progr ammer 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_Keit h) 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
5909
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
2398
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
5989
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(); value = value + 2; number = number + 2;
11
8278
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
5081
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 suggested in a faq, but it still doesnt seem to work. Below is what I have done: pid = fork() if (pid == 0){ printf ("http://my.wait.page"); exit (100);
3
2719
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 main() { .... pid1 = fork(); if (pid1) pid2 = fork(); .....
5
12232
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 recently explained it to a friend of mine and at that time decided to see if I could replicate it in C#. I have created an application that, to me at least, mimics what fork would/should do on *nix/bsd systems. I know that fork spawns a new...
3
5687
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 process I launch with execv the pppd to connect an embedded system to internet. The problem is that pppd fails. I have made two test program just to discard bugs (my applications is really big) and the result is that when I call execv from a...
9
5265
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 the calling script is stuck until the Python script ends: sys.stdout = open(os.devnull, 'w')
2
4244
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 copy of the address space of the parent. On success, both processes continue execution at the instruction after the fork call, with one difference, the return code for the fork system call is zero for the child process, while the process identifier of...
0
9521
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9333
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10107
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9945
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9900
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8768
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7324
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
3442
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.