Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > why i value doesn't change ?

Reply
Thread Tools

why i value doesn't change ?

 
 
sophia.agnes@gmail.com
Guest
Posts: n/a
 
      11-25-2007
Dear all,

consider the following program

#include<stdio.h>
#include<unistd.h>

main()
{
int pid,*i,j;

i = &j;
*i= 10;

pid = fork();

if(pid == 0)
{
printf("\n address of i = %p",i);
printf("\n initially i value in child = %d",*i);
*i = *i +10;
printf("\n after incrementation i value in child = %d",*i);
puts("Child terminated....");
}
else
{
wait( (int*) 0);

printf("\n address of i = %p",i);
printf("\n value of i in parent = %d",*i);
}

i am getting o/p as:-

address of i = 0xbfe6c01c
initially i value in child = 10
after incrementation i value in child = 20
Child terminated....

address of i = 0xbfe6c01c
value of i in parent = 10

the address of i is same in both parent and child process but
the change made in child process is not reflected in the
parent process why ?
 
Reply With Quote
 
 
 
 
Marco Manfredini
Guest
Posts: n/a
 
      11-25-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> the address of i is same in both parent and child process but
> the change made in child process is not reflected in the
> parent process why ?


Looks like you have yet to understand what "process" means or fork()
does. On many system, in particular those which have "fork()", every
process has it's own memory, the OS sets things up that the memory
address 0xbfe6c01c in process A points to a different RAM address than
the same address in process B. That way every process can assume that
nobody else will write into the memory of the process.

You need threads or shared memory on these systems, if you want
concurrent modification.
 
Reply With Quote
 
 
 
 
Willem
Guest
Posts: n/a
 
      11-25-2007
(E-Mail Removed) wrote:
) the address of i is same in both parent and child process but
) the change made in child process is not reflected in the
) parent process why ?

Suppose you're living in a house. You turn the bathroom light on. Then,
your kid goes to live on her own, a few houses down the block. She decides
to turn the bathroom light off, and she then writes in her blog 'I just
turned off the bathroom light'. You check if this is true, but for some
odd reason the bathroom light is still on.

How is this possible ? The bathroom light switch is at exactly the same
location in the house, after all.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      11-25-2007
(E-Mail Removed) wrote:
>
> consider the following program
>
> #include<stdio.h>
> #include<unistd.h>


Reading stops here. There is no <unistd.h> in ISO standard C, so
you are off topic. Try a Unix or Linux group.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      11-25-2007
In article <fic5j1$63s$(E-Mail Removed)>,
Marco Manfredini <(E-Mail Removed)> wrote:
>(E-Mail Removed) wrote:
>
>> the address of i is same in both parent and child process but
>> the change made in child process is not reflected in the
>> parent process why ?

>
>Looks like you have yet to understand what "process" means or fork()
>does. On many system, in particular those which have "fork()", every
>process has it's own memory, the OS sets things up that the memory
>address 0xbfe6c01c in process A points to a different RAM address than
>the same address in process B. That way every process can assume that
>nobody else will write into the memory of the process.


What? No standard CLC answers? Nobody pointing out that some of the
putative header files mentioned in this post do not exist - are not C,
etc, etc? No pointing out that we have no idea what "fork" (and, for
that matter, what about "spoon" and "knife") and "wait" (and "hesitate",
"stop", and others...) are? Pointing out that we would need the OP to
supply complete source code (in completely compliant ANSI C, of course)
for these totally unknown functions, before we can even consider
responding?

Come on, guys. You're slipping...

>You need threads or shared memory on these systems, if you want
>concurrent modification.


All completely OT, of course.

 
Reply With Quote
 
Marco Manfredini
Guest
Posts: n/a
 
      11-25-2007
Kenny McCormack wrote:
>
> What? No standard CLC answers? Nobody pointing out that some of the
> putative header files mentioned in this post do not exist - are not C,
> etc, etc? No pointing out that we have no idea what "fork" (and, for
> that matter, what about "spoon" and "knife") and "wait" (and "hesitate",
> "stop", and others...) are? Pointing out that we would need the OP to
> supply complete source code (in completely compliant ANSI C, of course)
> for these totally unknown functions, before we can even consider
> responding?


I'm just a curios visitor, bewildered by the customs of the local
natives. Anyway, I could point out that this question *is* on-topic,
because the OP found an external library function which seems to
undermine C's memory model *completely*, an inexplicable behavior. A
beginner may even wonder, if his/her inchoate proficiency of the
language is the cause of a fallacy only resolvable by the courtesy of
the knowing.

cheers
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      11-25-2007
Kenny McCormack wrote:
> In article <fic5j1$63s$(E-Mail Removed)>,
> Marco Manfredini <(E-Mail Removed)> wrote:
>> (E-Mail Removed) wrote:
>>
>>> the address of i is same in both parent and child process but
>>> the change made in child process is not reflected in the
>>> parent process why ?

>> Looks like you have yet to understand what "process" means or fork()
>> does. On many system, in particular those which have "fork()", every
>> process has it's own memory, the OS sets things up that the memory
>> address 0xbfe6c01c in process A points to a different RAM address than
>> the same address in process B. That way every process can assume that
>> nobody else will write into the memory of the process.

>
> What? No standard CLC answers? Nobody pointing out that some of the
> putative header files mentioned in this post do not exist - are not C,
> etc, etc? No pointing out that we have no idea what "fork" (and, for
> that matter, what about "spoon" and "knife") and "wait" (and "hesitate",
> "stop", and others...) are? Pointing out that we would need the OP to
> supply complete source code (in completely compliant ANSI C, of course)
> for these totally unknown functions, before we can even consider
> responding?
>
> Come on, guys. You're slipping...
>


Its sunday...

Happily they are sleeping late

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      11-25-2007
Marco Manfredini wrote:
>

.... snip ...
>
> I'm just a curios visitor, bewildered by the customs of the local
> natives. Anyway, I could point out that this question *is*
> on-topic, because the OP found an external library function which
> seems to undermine C's memory model *completely*, an inexplicable
> behavior. A beginner may even wonder, if his/her inchoate
> proficiency of the language is the cause of a fallacy only
> resolvable by the courtesy of the knowing.


This has nothing to do with the topicality, which is restricted to
ISO standard C. The 'finding' of another external library doesn't
affect that. As long as questions etc. deal with standard C we all
know what the basis is, and no guesswork is needed.

The 'knowing' can be restricted to the reading of the standard,
which is generally available. However, this may be fairly tough on
the newbie.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      11-26-2007
In article <fical3$j6a$(E-Mail Removed)>, Kenny McCormack
<(E-Mail Removed)> wrote on Sunday 25 Nov 2007 10:46 pm:

> In article <fic5j1$63s$(E-Mail Removed)>,
> Marco Manfredini <(E-Mail Removed)> wrote:
>>(E-Mail Removed) wrote:
>>
>>> the address of i is same in both parent and child process but
>>> the change made in child process is not reflected in the
>>> parent process why ?

>>
>>Looks like you have yet to understand what "process" means or fork()
>>does. On many system, in particular those which have "fork()", every
>>process has it's own memory, the OS sets things up that the memory
>>address 0xbfe6c01c in process A points to a different RAM address than
>>the same address in process B. That way every process can assume that
>>nobody else will write into the memory of the process.

>
> What? No standard CLC answers? Nobody pointing out that some of the
> putative header files mentioned in this post do not exist - are not C,
> etc, etc? No pointing out that we have no idea what "fork" (and, for
> that matter, what about "spoon" and "knife") and "wait" (and
> "hesitate", "stop", and others...) are? Pointing out that we would
> need the OP to supply complete source code (in completely compliant
> ANSI C, of course) for these totally unknown functions, before we can
> even consider responding?
>
> Come on, guys. You're slipping...


Not to worry. It was a slight oversight, now rectified.

 
Reply With Quote
 
Joachim Schmitz
Guest
Posts: n/a
 
      11-26-2007
"CBFalconer" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
> (E-Mail Removed) wrote:
>>
>> consider the following program
>>
>> #include<stdio.h>
>> #include<unistd.h>

>
> Reading stops here. There is no <unistd.h> in ISO standard C, so
> you are off topic. Try a Unix or Linux group.

Which she did...

Bye, Jojo


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
A Paradise DNS address change? What change? There was no change. Tony Neville NZ Computing 7 09-22-2006 01:02 PM
Change the value of an attribute according to the value of another attribute patrizio.trinchini@googlemail.com XML 8 08-22-2006 02:53 PM
Radio Button lost it`s checked value after few time change value BobbyMy ASP .Net Web Controls 0 08-27-2005 03:04 AM



Advertisments