Linux-Bulgaria.ORG
навигация

 

начало

пощенски списък

архив на групата

семинари ...

документи

как да ...

 

 

Предишно писмо Следващо писмо Предишно по тема Следващо по тема По Дата По тема (thread)

Re: lug-bg: system()


  • Subject: Re: lug-bg: system()
  • From: mitko@xxxxxxx (Dimitar Peikov)
  • Date: Sun, 5 May 2002 16:28:44 +0300



On Sun, 5 May 2002 15:07:22 +0300
"Ilia Trendafilov" <edac@xxxxxxxxxxx> wrote:

>     Zdraveite,
>   Kak moga da ubia process pusnat ot programa chrez system()? Ideiata
>   e ako procesa ne e grymnal sled niakolko sekundi da se ubiva rychno.
>   Zasega edinstvenoto smisleno neshto do koeto uspiah da stigna e
>   neshto ot roda
> 
> signal(SIGALRM,killchild);
> alarm(3);
> system("wa");
> signal(SIGALRM,SIG_DFL);

Ne ti preporuchvam da polzvash system(), mozesh da beresh jadove. Po dobra realizacia e fork() - exec(), kato v tozi varian njama da ti se nalozi da pravish evristiki po koj proces trjabva da streljash s pushkata kill().

> 
> Vyprosyt e kakvo tochno da sydyrja procedurata killchild(), taka che
> da ubiva. Ne e zadyljitelno za celta da se izpolzva system(), no tova
> mi se vijda po-prosto ot fork() i exec()-proizvodni funkcii, pyk i
> dori da izpolzvam exec() pak ne moga da se setia za nachin da grymna
> procesa.  Pak v syshtia duh - kak moga da ogranicha po niakakyv nachin
> pametta izpolzvana ot vyprosnia child process do niakakvi tvyrdi
> granici naprimer 16MB data size i 1MB stack. Znam za setrlimit(), samo

Viz primera po dolu. Ako v 'ulimit -a' imash njakakvi po malki ogranichenja tova njama da sraboti (man getrlimit)!

----------------------------
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>

int zzz() {
  struct rlimit my_limit;

  if (getrlimit(RLIMIT_DATA, &my_limit) != 0) {
        /* Error */
        return -1;
  }

  printf("RLIMIT_DATA: %u %u\n", my_limit.rlim_cur, my_limit.rlim_max);

  if (getrlimit(RLIMIT_STACK, &my_limit) != 0) {
        /* Error */
        return -1;
  }

  printf("RLIMIT_STACK: %u %u\n", my_limit.rlim_cur, my_limit.rlim_max);

}

int xxx() {
  struct rlimit my_limit;

  my_limit.rlim_cur = 1024 * 16;
  my_limit.rlim_max = 1024 * 16;
  if (setrlimit(RLIMIT_DATA, &my_limit) != 0) {
        /* Error */
        return -1;
  }

  my_limit.rlim_cur = 1024 * 1;
  my_limit.rlim_max = 1024 * 1;
  if (setrlimit(RLIMIT_STACK, &my_limit) != 0) {
        /* Error */
        return -1;
  }

  return 0;
}

int main() {
  zzz();
  xxx();
  zzz();
}

----------------------------

> che (ne mi se smeite :) ne mojah da zacepia kak tochno raboti...
>   Blagodaria predvaritelno...
> =====================================================================
> ======= A mail-list of Linux Users Group - Bulgaria (bulgarian
> linuxers). http://www.linux-bulgaria.org - Hosted by Internet Group
> Ltd. - Stara Zagora To unsubscribe:
> http://www.linux-bulgaria.org/public/mail_list.html
> =====================================================================
> =======


-- 
Dimitar Peikov
Programmer Analyst
Globalization Group
"We Build e-Business"  

RILA Solutions  
27 Building, Acad.G.Bonchev Str.  
1113 Sofia, Bulgaria  

phone: (+359 2) 9797320 
phone: (+359 2) 9797300 
fax:   (+359 2) 9733355  
http://www.rila.com 
============================================================================
A mail-list of Linux Users Group - Bulgaria (bulgarian linuxers).
http://www.linux-bulgaria.org - Hosted by Internet Group Ltd. - Stara Zagora
To unsubscribe: http://www.linux-bulgaria.org/public/mail_list.html
============================================================================



  • Във връзка с:
  • Относно:

 

наши приятели

 

линукс за българи
http://linux-bg.org

FSA-BG
http://fsa-bg.org

OpenFest
http://openfest.org

FreeBSD BG
http://bg-freebsd.org

KDE-BG
http://kde.fsa-bg.org/

Gnome-BG
http://gnome.cult.bg/

проект OpenFMI
http://openfmi.net

NetField Forum
http://netField.ludost.net/forum/

 

 

Linux-Bulgaria.ORG

Mailing list messages are © Copyright their authors.