From: Subhobroto Sinha <[EMAIL PROTECTED]>

I wanna know indepth about the COW implementation of
fork() in Linux 2.4 and higher - all including page
table stuff..

You need a book ;) not a LUG for that.

Oh, and a quickie :

When we print an address of a variable, is it the
virtual address or the physical one which is printed ?

        printf("%04X", &i); /* Is virtual address of 'i'

This statement invokes UB. See below.

printed or the physical one ?*/

And what exactly do you mean by virtual/physical address?

Methinks it's the virtual address as from the page
table. Am I right ?

AFAIK, C does not have any idea of virtual/physical address.

If you didn't get it, or think I am on dope, consider
this :

#include <stdio.h>

int main()
{
        int i = 5, pid, count, *p = &i;

        char choice[4] = {0};

        printf("\ni = %d (%X)\n", i, &i);

        printf("\nFork ?\n");

        scanf("%s", choice);

        if(choice[0] == 'y')
        {
                pid = fork();

                if(pid < 0)
                {
                        printf("\nfork() failed\n");
                }
                else if(pid == 0)
                {
                        i = 6;
                        printf("\nChild : %d (%X)\n", i, &i);
                }
                else
                {
                        printf("\n[1]Spawned child pid = %d, i = %d
(%X)\n", pid, i, &i);
                        wait(0);
                        printf("\n[2]Spawned child pid = %d, i = %d
(%X)\n", pid, i, &i);
                        printf("\nDone waiting for child\n");
                }

                printf("{%d} ", pid);

                for(count = 0; count < 10; ++count, --p) printf("%x
", *p);

                printf("\n{%d}i : %d (%X)\n", pid, i, &i);
        }

        return 0;
}

Look at it closely, and match it with the output. Who
can explain that to me ?


Did you try to compile this? Here are the results of my efforts:
gcc -std=c99 -W -Wall -pedantic -ansi Test.c

Test.c:29: warning: format '%X' expects type 'unsigned int', but argument 3 has type 'int *'
  Test.c:37: warning: implicit declaration of function 'fork'
Test.c:46: warning: format '%X' expects type 'unsigned int', but argument 3 has type 'int *' Test.c:50: warning: format '%X' expects type 'unsigned int', but argument 4 has type 'int *'
  Test.c:51: warning: implicit declaration of function 'wait'
Test.c:52: warning: format '%X' expects type 'unsigned int', but argument 4 has type 'int *' Test.c:60: warning: format '%X' expects type 'unsigned int', but argument 4 has type 'int *'

Hints:

*) man scanf / `p' conversion specifier, and the need to cast it to (void *)
*) header inclusion


Regards,
Suman.




--
To unsubscribe, send mail to [EMAIL PROTECTED] with the body
"unsubscribe ilug-cal" and an empty subject line.
FAQ: http://www.ilug-cal.org/node.php?id=3

Reply via email to