Quote:
why the whole system can get the new locale data?
|
It doesn't. If you run this bash script:
Code:
#!/bin/bash
cat > wje.c <<EOD
#include <sys/types.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(void)
{
char *duplicated_locale_name;
char *returned_locale_name;
pid_t child_process;
printf(" parent process is %d\n",getpid());
child_process=fork();
if(child_process<0)
{
perror("first fork()");
exit(1);
}
if(child_process==0)
{
sleep(3);
if(setlocale(LC_ALL,"de_DE")==NULL)
{
fprintf(stderr,"setlocale() failed in process %d\n",getpid());
exit(1);
}
printf("setlocale() succeeded in process %d\n",getpid());
sleep(3);
}
else
{
printf("first child process is %d\n",child_process);
child_process=fork();
if(child_process<0)
{
perror("second fork()");
exit(1);
}
if(child_process==0)
{
sleep(9);
}
else
{
printf("second child process is %d\n",child_process);
sleep(12);
}
}
returned_locale_name=setlocale(LC_ALL,NULL);
duplicated_locale_name=strdup(returned_locale_name);
printf("for process %d, current locale is %s\n",
getpid(),
duplicated_locale_name
);
return 0;
} /* main() */
EOD
cc -Wall wje.c -o wje
./wje
you should get output like this:
Code:
parent process is 15900
first child process is 15901
second child process is 15902
setlocale() succeeded in process 15901
for process 15901, current locale is de_DE
for process 15902, current locale is C
for process 15900, current locale is C
with three-second pauses before each of the final four lines.