LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-14-2009, 12:38 AM   #1
xhsoldier
LQ Newbie
 
Registered: Jan 2009
Posts: 12

Rep: Reputation: 0
how linux publish the locale data to the system


Using function setlocale (int category, const char *locale)
will set the locale in my application, and then the whole system will use this new locale.

why the whole system can get the new locale data?

They are in the different process.

Last edited by xhsoldier; 01-14-2009 at 12:57 AM. Reason: title unproper
 
Old 01-14-2009, 05:10 AM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
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.
 
Old 01-19-2009, 08:38 PM   #3
xhsoldier
LQ Newbie
 
Registered: Jan 2009
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks for your reply.

There is a system wide locale,right?
why all the process can access this system wide locale?
Is this system wide locale stored in a File? Possible not, it is too slow.
Where is it? In RAM, Maybe.But If it is in a RAM, How to protect the locale data?
 
Old 01-19-2009, 09:48 PM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
How is the locale initially set for each process? Where are the files that determine this? The answer varies from one Linux distribution to another.

But changing the locale in a process by using setlocale() does not change any of those files.
 
Old 01-19-2009, 10:20 PM   #5
xhsoldier
LQ Newbie
 
Registered: Jan 2009
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by wje_lq View Post
How is the locale initially set for each process? Where are the files that determine this? The answer varies from one Linux distribution to another.

But changing the locale in a process by using setlocale() does not change any of those files.

I do not know. Can you just give an example? On how all the process can access the system wide locale?
 
  


Reply

Tags
locale



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change the locale by setting the system default locale letdoit Slackware 6 08-18-2011 03:34 AM
You are subscribed to this thread Connection reset by peer (S: vsftpd, C: gftp) baosheng Linux - Networking 1 05-13-2006 10:18 AM
make 'you are subscribed to this thread' a link nadroj LQ Suggestions & Feedback 5 02-03-2006 09:15 PM
No email notifications for replies or subscribed thread redhatrosh LQ Suggestions & Feedback 10 06-24-2005 10:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration