473,804 Members | 3,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why i value doesn't change ?

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 ?
Nov 25 '07 #1
33 1813
so**********@gm ail.com 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.
Nov 25 '07 #2
so**********@gm ail.com 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
Nov 25 '07 #3
In article <fi**********@a ioe.org>,
Marco Manfredini <ok**********@p hoyd.netwrote:
>so**********@g mail.com 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.

Nov 25 '07 #4
so**********@gm ail.com wrote:
>
consider the following program

#include<stdio. h>
#include<unistd .h>
Reading stops here. There is no <unistd.hin 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

Nov 25 '07 #5
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
Nov 25 '07 #6
Kenny McCormack wrote:
In article <fi**********@a ioe.org>,
Marco Manfredini <ok**********@p hoyd.netwrote:
>so**********@gm ail.com 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
Nov 25 '07 #7
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

Nov 25 '07 #8
In article <fi**********@n ews.xmission.co m>, Kenny McCormack
<ga*****@xmissi on.xmission.com wrote on Sunday 25 Nov 2007 10:46 pm:
In article <fi**********@a ioe.org>,
Marco Manfredini <ok**********@p hoyd.netwrote:
>>so**********@ gmail.com 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.

Nov 26 '07 #9
"CBFalconer " <cb********@yah oo.comschrieb im Newsbeitrag
news:47******** *******@yahoo.c om...
so**********@gm ail.com wrote:
>>
consider the following program

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

Reading stops here. There is no <unistd.hin ISO standard C, so
you are off topic. Try a Unix or Linux group.
Which she did...

Bye, Jojo
Nov 26 '07 #10

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

Similar topics

3
8903
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns a empty value instead of returning the browser type. Here is the line which i am using in my code and from manual: <?php echo $_SERVER; ?>
23
63703
by: stewart.midwinter | last post by:
No doubt I've overlooked something obvious, but here goes: Let's say I assign a value to a var, e.g.: myPlace = 'right here' myTime = 'right now' Now let's say I want to print out the two vars, along with their names. I could easily do this: print "myPlace = %s, myTime = %s" % (myPlace, myTime)
12
4913
by: Anna | last post by:
Hi all, I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try.... in case you should see it later I apologize for posting the same question twice! Here it is: I am having problems reading the value of a text Node. I think it has to do with the fact that the text is in a <span> tag. I have a table and in each <td> I have text + a checkbox. I want to retreive the text next to the...
21
2439
by: Steven T. Hatton | last post by:
I'm trying to improve my formal understanding of C++. One significant part of that effort involves clarifying my understanding of the vocabulary used to describe the language. This is from the C++ Standard: "" "...sequence of operators and operands that specifies a computation...". That means to me that an expression can be "executed". I am purposely
17
479
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I get the value of a form control? ----------------------------------------------------------------------- In HTML documents, named forms may be referred to as named properties of the « document.forms » collection, and named form controls may be referred to as named properties of the form's elements collection: var frm = document.forms;
2
2022
by: Gary Dale | last post by:
I have a form with a pull-down list with six options, each of which has a value set. The value is the e-mail account name (without the domain) of a group while the displayed value is the full name of the group that will receive the e-mail. I pass this.form to a function to validate the other data before handing it off to a script to actually do the mailing. The mailer script looks at all of the form's fields and sends their names and...
2
2322
by: sparks | last post by:
I am trying to set the default value on a forms field to the filter that I am passing to the form. The filter works fine but the field comes up blank. So I put in a default value and it works fine. But I need to change the default value for the field each time I pass it a filter. so on the switchboard I build for this mess I have 8 buttons and each button does this
8
9674
by: grpramodkumar | last post by:
HI, function change(value,sub) { subcat = document.getElementById(sub); subcat.options.value = value; }
45
18919
by: Zytan | last post by:
This returns the following error: "Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.this' because it is not a variable" and I have no idea why! Do lists return copies of their elements? Why can't I change the element itself? class Program { private struct MyStruct
43
3237
by: kenneth | last post by:
Dear all, I have encountered this weird problem. I have a class definition with an __init__ argument 'd' which defaults to {}. This argument is put in the 'self.d' attribute at initialization I create two independent instances of this class; the code is as follows.
0
9708
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
9588
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
10589
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
10340
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
10327
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
9161
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
7625
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...
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.