Re: [Linux-programlama] yivli getpwuid_r() kullanımı

---------

New Message Reply About this list Date view Thread view Subject view Author view Attachment view

From: Cafer Şimşek (cfb@cafer.org)
Date: Sat 14 Jan 2006 - 22:48:52 EET


cfb@cafer.org (Cafer Şimşek) writes:

> Volkan YAZICI <yazicivo@ttnet.net.tr> writes:
>
>> Merhaba,
>>
>> İç içe yivlerin (thread) bulunduğu bir programda getpwuid_r()
>> çağrıları hep başıma iş açıyor. (Ufak betiği ekte gönderiyorum.)
>> "ps -p <PID> -o rss,size" komutu ile işlemin bellek kullanımına
>> baktığımda (bilmem ps yöntemi ne kadar duyarlı sonuç verir) SIZE
>> değeri sabit kalırken, RSS devamlı büyüyor.
>>
>
> Selam,
>
>
> [...]
>
>
>>
>> void *
>> sub_func(void *tmp)
>> {
>> int ret;
>> size_t sz = 128;
>> char buf[sz];
>>
>> struct passwd old_pw;
>> struct passwd *new_pw;
>>
>> ret = getpwuid_r(proc_id, &old_pw, buf, sz, &new_pw);
>
> bu satırda bir sorun olabilir mi?. new_pw için ayrılmış bir alan
> yok. Emin değilim ama genelde parametre olarak adres geçilen
> fonksiyonlar kendileri bellek tahsisi yapmazlar. Tanımlama işini;
>
> struct passwd *new_pw = (struct passwd*) malloc(sizeof(struct passwd));
>
> şeklinde yapıp işiniz bitince de free() yapsanız daha mantıklı olmaz
> mı?
>

Az önce man'a baktım da, az önceki yazdıklarımı unutun :)

>
>
>> if (ret)
>> fprintf(stderr, "getpwuid_r() failed! ret = %d\n", ret);
>>
>> pthread_exit(NULL);
>> }
>>
>> int
>> main(void)
>> {
>> int loop_count = 50;
>> int thread_count = 100;
>> pthread_t threads[thread_count];
>> int i, ret;
>>
>> proc_id = getpid();
>> sprintf(cmd, "ps -p %d -o rss,size", proc_id);
>>
>> while (loop_count--)
>> {
>> for (i = 0; i < thread_count; i++)
>> {
>> ret = pthread_create(&threads[i], NULL, sub_func, NULL);
>> if (ret)
>> fprintf(stderr, "pthread_create() failed! i = %d, ret = %d\n", i, ret);
>> }
>>
>> for (i = 0; i < thread_count; i++)
>> {
>> ret = pthread_join(threads[i], NULL);
>> if (ret)
>> fprintf(stderr, "pthread_join() failed! i = %d, ret = %d\n", i, ret);
>> }
>>
>> print_mem_usage();
>> }
>>
>> return 0;
>> }
>> _______________________________________________
>> Linux-programlama mailing list
>> Linux-programlama@liste.linux.org.tr
>> http://liste.linux.org.tr/mailman/listinfo/linux-programlama
>
> --
> Stallman amcamız sağolsun
>
> Cafer 'cfb' Şimşek
> http://cafer.org
> _______________________________________________
> Linux-programlama mailing list
> Linux-programlama@liste.linux.org.tr
> http://liste.linux.org.tr/mailman/listinfo/linux-programlama

-- 
bu imza için sponsor aranıyor

Cafer 'cfb' Şimşek http://cafer.org

_______________________________________________
Linux-programlama mailing list
Linux-programlama@liste.linux.org.tr
http://liste.linux.org.tr/mailman/listinfo/linux-programlama


New Message Reply About this list Date view Thread view Subject view Author view Attachment view

---------

Bu arsiv hypermail 2.1.2 tarafindan uretilmistir.