Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-28-2002, 02:05 AM   #1
LQ Newbie
Registered: Jan 2002
Location: Memphis
Distribution: Redhat 7.2
Posts: 23

Rep: Reputation: 15
child and parent process error

plz help me..
.same address is used by k in parent and child.(it is wrong). why is that so...? is there any error in the progam..?


#define SHM_SIZE 1024 /* make it a 1K shared memory segment */

unsigned char *str;
void test(int *);

int main()
int a;
printf("\nIn Main: the address of a: %u\n",&a);

void test(int *k)
pid_t pid;
long z;

if((pid=fork())==0) { // child
printf("In Child\n");
printf(" child k = %lu\n", k);
printf(" child *k = %d\n", *k);
printf(" child increased k = %lu\n",k);
else { // server
printf("In Parent\n");
printf(" parent k = %lu\n", k);
printf(" parent *k = %d\n", *k);
printf(" parent increased k = %lu\n",k);


void itoa(long n, char *s)
char temp[20];
int i=0,j=0,len;
temp[i++] = n%10 + '0';
while (n/=10);
len = strlen(temp);
s[j] = temp[len-j-1];
Old 04-29-2002, 08:13 AM   #2
Senior Member
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 47
What are you trying to do. Changing the contents of the variable in the server won't change the one in the client. The client gets a copy of the servers data segment as far as I know.

I think k=k+1 should be *k+=1


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
When I kill parent process, child isn't killed BengeBoy Linux - Software 0 08-19-2004 04:38 PM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 01:19 PM
parent and child processes skora Programming 5 11-02-2003 10:41 AM
about parent and child process winwar Solaris / OpenSolaris 3 07-23-2003 06:07 AM
child-parent-&-fork mukul Programming 2 03-24-2001 01:12 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:15 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration