fork e memoria
Stefano Di Paola <[email protected]> Mon, 29 Nov 2004 13:34:50 +0100
| Newsgroups | gmane.comp.security.italian.devel |
|---|---|
| Message-ID | <1101731690.5068.26.camel@pc999> |
--===============0265132140==
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Ciao a tutti,
sto facendo un po' di ricerca sugli aspetti di sicurezza della fork.
Non capisco una cosa. Come mai quando debuggo un processo figlio
vedo lo stesso spazio di memoria del padre ma una modifica da parte del
processo figlio non e' rilevato dal processo padre?
Ad es.:
//forkit.c
void main(int argc, char **argv)
{
pid_t id;
int *x , x1;
x=(int *)malloc(sizeof(int));
*x=3;
x1=2;
printf("Parent: before fork x = %d &x=%x x1=%d &x1=%x\n",
*x,x,x1,&x1);
id = fork();
if (id == 0) {
printf("Child: id = %d\n", id);
printf("Child: x = %d &x=%x x1=%d &x1=%x\n", *x,x,x1,&x1);
*x=99;
x1=99;
printf("Child: x = %d &x=%x x1=%d &x1=%x\n", *x,x,x1,&x1);
exit(0);
} else {
/* we are in the parent */
printf("Parent: id = %d\n", id);
printf("Parent: wait for child\n");
id = wait(NULL);
printf("Parent: child terminated pid = %d\n", id);
printf("Parent: x = %d &x=%x x1=%d &x1=%x\n", *x,x, x1,&x1);
}
}
$ ./forkit
Parent: before fork x = 3 &x=80498f0 x1=2 &x1=bffff6fc
Parent: id = 6823
Parent: wait for child
Child: id = 0
Child: x = 3 &x=80498f0 x1=2 &x1=bffff6fc
Child: x = 99 &x=80498f0 x1=99 &x1=bffff6fc
Parent: child terminated pid = 6823
Parent: x = 3 &x=80498f0 x1=2 &x1=bffff6fc
Saluti e grazie in anticipo!
Stefano
--------------------------------
Stefano Di Paola
Ingegnere Informatico
Email: stefano.dipaola_at_wisec.it
Web: http://www.wisec.it
--------------------------------
--===============0265132140==
Content-Type: text/plain; charset="iso-8859-1"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
________________________________________________________
http://www.sikurezza.org - Italian Security Mailing List
--===============0265132140==--