linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* task_struct and uid of a task
@ 2003-12-31  5:13 auntvini
  2003-12-31  6:15 ` Rusty Russell
  0 siblings, 1 reply; 5+ messages in thread
From: auntvini @ 2003-12-31  5:13 UTC (permalink / raw)
  To: rusty; +Cc: linux-kernel

Hi Rusty,

I hope I am not disturbing you.

I am building the linux kernel to calculate the Load Average of the tasks 
in a different manner.

That would be to separate the tasks under respective login user and then 
calculate Load Averages. I was successful partly but there is a problem.

ps command gives a good idea  about my effort.

Though I was able to introduce new code, now I find that as far as a child 
processors are concerned uid is not the original user id (say 500, 501 etc) 
of that child processor. This is because the child inherits the user id of 
the Parent.

As a result of that my separation of tasks under differant users is not 
accurate.

Previously I thought that the uid in the struct task_struct
is going to be original user id. Now I find it is not the case always as 
child inherits parent uid

Then I used p->uid. which is not true.


Do you know any global structure that keeps the original user id (say 500, 
501 etc)?

Or I may have to introduce another variable in this regard.

Thanks
Sena Seneviratene
Computer Engineering Lab
Sydney University


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: task_struct and uid of a task
  2003-12-31  5:13 task_struct and uid of a task auntvini
@ 2003-12-31  6:15 ` Rusty Russell
  0 siblings, 0 replies; 5+ messages in thread
From: Rusty Russell @ 2003-12-31  6:15 UTC (permalink / raw)
  To: auntvini; +Cc: linux-kernel

In message <5.1.1.5.2.20031231155606.03376908@brain.sedal.usyd.edu.au> you write:
> Previously I thought that the uid in the struct task_struct
> is going to be original user id. Now I find it is not the case always as 
> child inherits parent uid
> 
> Then I used p->uid. which is not true.

It should be true for non-root users, except for setuid programs which
can alter it.

> Do you know any global structure that keeps the original user id (say 500, 
> 501 etc)?
> 
> Or I may have to introduce another variable in this regard.

I'm not sure what problem you are having.  There are only two real
ways that uids can change: setuid programs, and root calling setuid or
setreuid.

Adding another variable which contained the "original, unchanged" uid
doesn't really make sense, since it would always be 0, the uid of
init.

A little confused, but I hope that helps,
Rusty.
--
  Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: task_struct and uid of a task
       [not found] ` <20031231124528.GA2837@lnx-holt>
  2004-01-04 14:34   ` sena
@ 2004-01-04 15:19   ` sena
  1 sibling, 0 replies; 5+ messages in thread
From: sena @ 2004-01-04 15:19 UTC (permalink / raw)
  To: Robin Holt; +Cc: linux-kernel

Hi Robin,

I have applied this to my local testing code and indendation is looking 
perfectly good.

indent -kr -i8 -psl -npcs -cp9 loadavg.c

Robin Thanks a lot for that.

Sena Seneviratne
Computer engineering Lab
Sydney University
Sydney



Robin Holt wrote:

>On Wed, Dec 31, 2003 at 07:06:52AM +1100, sena wrote:
>
>Sena,
>
>Why don't you pester me about this instead of bothering Rusty.
>
>What are you trying to accomplish?  Please be specific about what
>you are trying to find out and not how you are trying to do it.
>
>Another thing, I would _GREATLY_ appreciate code which has
>decent variable names and good indentation.  Assuming you are
>writing this on a Linux box with a standard development install,
>you should be able to do:
>
>indent -kr -i8 -psl -npcs -cp9 myfile.c
>
>and get very kernel-style code.  Won't fix the variable names, but
>at least braces will be indented.
>
>Thanks,
>Robin Holt
>
>  
>
>>Dear Rusty,
>>
>>Thank you for your previous reply. I feel like you would be able to 
>>assist me.
>>
>>Say a computer has 5 user logins name1(500), name2(501), 
>>name3(502).........name5(504) apart from root. If these 5 people 
>>remotely login and runs there jobs, then the user name of those jobs are 
>>name1,name2 and name3.
>>
>>Say if they use telnet to remotely login then those Tasks will be 
>>started under telnet server as children.
>>
>>As the children inherits uid, euid etc of the parents. That means telnet 
>>is run as root and it inherits uid<500.
>>
>>task_struct has uid and it is updated accordingly.
>>
>>
>>I have built the kernel 2.4.19sena1 successfully but this is my problem. 
>>The problem because child process inherits uid etc if I start any 
>>process through telnet
>>
>>My code is as follows:
>>
>>unsigned long a; //for root uid<500, I am getting this uidArray[0] is 
>>for storing uid (assumed 100 for all <500)
>>unsigned long b; //for 500
>>unsigned long c; //for 501
>>unsigned long d; //for 502
>>unsigned long e; //for 503
>>unsigned long f; // for 504
>>
>>unsigned int uidArray[7];
>>
>>static unsigned long count_active_tasks(void)
>>{
>>   struct task_struct *p;
>>   unsigned long nr = 0;
>>
>>   int s = 0;
>>  
>>   int i=0;
>>   int j=0;
>>   int k=0;
>>   int m=0;
>>
>>   a=b=c=d=e=f=0;
>>  
>>      read_lock(&tasklist_lock);
>>
>>   for_each_task(p)
>>   {
>>       if ((p->state == TASK_RUNNING ||
>>            (p->state & TASK_UNINTERRUPTIBLE)))
>>   {
>>
>>       nr += FIXED_1; //nr total tasks
>>      
>>       if(i==0)
>>       {
>>           uidArray[0] = 100;
>>
>>           if(p->uid < 500)
>>           {
>>          
>>           a += FIXED_1;
>>           }
>>           else
>>           {
>>           uidArray[1] = p->uid;
>>           b += FIXED_1;
>>           k++;
>>           }
>>        k++;
>>       }
>>       else
>>       {
>>          for(j=0; j < k ; j++)
>>          {
>>              
>>           if((j==0)&& (p->uid < 500) && (s==0))
>>           {
>>               a += FIXED_1;
>>               s = 1;
>>               break;
>>           }
>>           else if((uidArray[j] == p->uid) && s==0)
>>           {
>>               if(j==1){
>>               b += FIXED_1;}
>>               if(j==2){
>>               c += FIXED_1;}
>>               if(j==3){
>>               d += FIXED_1;}
>>               if(j==4){
>>               e += FIXED_1;}
>>               if(j==5){
>>               f += FIXED_1;}
>>               s=1;
>>               break;
>>           }
>>           }
>>  
>>           if(s==0)
>>           {
>>
>>           if(k < 6)
>>              {
>>               k++;
>>               j = k-1;
>>               uidArray[j] = p->uid;
>>               if(j==1){
>>               b += FIXED_1;}
>>               if(j==2){
>>               c += FIXED_1;}
>>               if(j==3){
>>               d += FIXED_1;}
>>               if(j==4){
>>               e += FIXED_1;}
>>               if(j==5){
>>               f += FIXED_1;}
>>              }
>>              
>>
>>           }
>>
>>       s=0;
>>         }
>>      
>>       i++;
>>  
>>   }
>>
>>   }
>>          
>>   read_unlock(&tasklist_lock);
>>   return nr;
>>
>>}
>>
>>unsigned long avenrun[6];
>>
>>unsigned long avenrunT;
>>
>>static inline void calc_load(unsigned long ticks)
>>{
>>   unsigned long active_tasks;  /*fixed-point */
>>   static int count = LOAD_FREQ;
>>
>>   count -= ticks;
>>   if (count < 0) {
>>       count += LOAD_FREQ;
>>       active_tasks = count_active_tasks();
>>
>>       CALC_LOAD(avenrunT, EXP_5, active_tasks);
>>       CALC_LOAD(avenrun[0], EXP_5, a);
>>       CALC_LOAD(avenrun[1], EXP_5, b);
>>       CALC_LOAD(avenrun[2], EXP_5, c);
>>       CALC_LOAD(avenrun[3], EXP_5, d);
>>       CALC_LOAD(avenrun[4], EXP_5, e);
>>       CALC_LOAD(avenrun[5], EXP_5, f);
>>      
>>   }
>>}
>>
>>I have updated all the other places(all .h and .c files) to suit this code.
>>
>>And the result is stored in    proc/loadavg as
>>
>>       0.21   0.21   100   0.00     0       0.00      0        0.00     
>>0        0.00     0            0.00        0
>>         T        a 1      uid     b1    500        c 1     501      d1 
>>    502      e1      503          f1         504
>>
>>T- for totall
>>a1- root or uid < 500
>>b1,c1,di etc for uid>=500
>>
>>In this perticular case I have login as root so that uid 100 is seen. 
>>There is no 500 or above. they are all 0.
>>
>>But even if I start login remotely those processors started through 
>>telnet inherits uid <500. Then they will be shown under a1
>>
>>I get uids from task_struct
>>
>>Thanks
>>Sena Seneviratne
>>Computer Engineering Lab
>>School of Electrical and Information Engineering
>>Sydney University
>>
>>-
>>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>>the body of a message to majordomo@vger.kernel.org
>>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>Please read the FAQ at  http://www.tux.org/lkml/
>>    
>>
>
>  
>




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: task_struct and uid of a task
       [not found] ` <20031231124528.GA2837@lnx-holt>
@ 2004-01-04 14:34   ` sena
  2004-01-04 15:19   ` sena
  1 sibling, 0 replies; 5+ messages in thread
From: sena @ 2004-01-04 14:34 UTC (permalink / raw)
  To: Robin Holt; +Cc: Rusty Russell, linux-kernel

Robin,

Thanks for your willingness to assist me. Then I will ask questions from 
you too.

I have already compiled the new kernel and it is up and running.

In my next kernel update I will follow your avice to naming and indentation.

One of my friends from India told me to direct this question to Rusty 
Russel as they are very impressed about his guidance.

Thus I will keep him as my main Guru.


What I intend to do is: This is to prove a point in a Research Paper.

I am going to count number of queued and runnable processes which 
belongs to each user login(uid). Then I would apply loadavg calculations 
seperately.

The problem is in task_struct. The uids in task_struct is parents uid 
(as some childs inherits it)

So if I go by that uid while counting the processes, then I would make a 
mistake.

At this stage in my newly compiled kernel, I find that mistake staight away.


Wishing you a Happy new Year

Sena Seneviratne
Computer Engineering Lab
Sydney University
Sydney


Robin Holt wrote:

>On Wed, Dec 31, 2003 at 07:06:52AM +1100, sena wrote:
>
>Sena,
>
>Why don't you pester me about this instead of bothering Rusty.
>
>What are you trying to accomplish?  Please be specific about what
>you are trying to find out and not how you are trying to do it.
>
>Another thing, I would _GREATLY_ appreciate code which has
>decent variable names and good indentation.  Assuming you are
>writing this on a Linux box with a standard development install,
>you should be able to do:
>
>indent -kr -i8 -psl -npcs -cp9 myfile.c
>
>and get very kernel-style code.  Won't fix the variable names, but
>at least braces will be indented.
>
>Thanks,
>Robin Holt
>
>  
>
>>Dear Rusty,
>>
>>Thank you for your previous reply. I feel like you would be able to 
>>assist me.
>>
>>Say a computer has 5 user logins name1(500), name2(501), 
>>name3(502).........name5(504) apart from root. If these 5 people 
>>remotely login and runs there jobs, then the user name of those jobs are 
>>name1,name2 and name3.
>>
>>Say if they use telnet to remotely login then those Tasks will be 
>>started under telnet server as children.
>>
>>As the children inherits uid, euid etc of the parents. That means telnet 
>>is run as root and it inherits uid<500.
>>
>>task_struct has uid and it is updated accordingly.
>>
>>
>>I have built the kernel 2.4.19sena1 successfully but this is my problem. 
>>The problem because child process inherits uid etc if I start any 
>>process through telnet
>>
>>My code is as follows:
>>
>>unsigned long a; //for root uid<500, I am getting this uidArray[0] is 
>>for storing uid (assumed 100 for all <500)
>>unsigned long b; //for 500
>>unsigned long c; //for 501
>>unsigned long d; //for 502
>>unsigned long e; //for 503
>>unsigned long f; // for 504
>>
>>unsigned int uidArray[7];
>>
>>static unsigned long count_active_tasks(void)
>>{
>>   struct task_struct *p;
>>   unsigned long nr = 0;
>>
>>   int s = 0;
>>  
>>   int i=0;
>>   int j=0;
>>   int k=0;
>>   int m=0;
>>
>>   a=b=c=d=e=f=0;
>>  
>>      read_lock(&tasklist_lock);
>>
>>   for_each_task(p)
>>   {
>>       if ((p->state == TASK_RUNNING ||
>>            (p->state & TASK_UNINTERRUPTIBLE)))
>>   {
>>
>>       nr += FIXED_1; //nr total tasks
>>      
>>       if(i==0)
>>       {
>>           uidArray[0] = 100;
>>
>>           if(p->uid < 500)
>>           {
>>          
>>           a += FIXED_1;
>>           }
>>           else
>>           {
>>           uidArray[1] = p->uid;
>>           b += FIXED_1;
>>           k++;
>>           }
>>        k++;
>>       }
>>       else
>>       {
>>          for(j=0; j < k ; j++)
>>          {
>>              
>>           if((j==0)&& (p->uid < 500) && (s==0))
>>           {
>>               a += FIXED_1;
>>               s = 1;
>>               break;
>>           }
>>           else if((uidArray[j] == p->uid) && s==0)
>>           {
>>               if(j==1){
>>               b += FIXED_1;}
>>               if(j==2){
>>               c += FIXED_1;}
>>               if(j==3){
>>               d += FIXED_1;}
>>               if(j==4){
>>               e += FIXED_1;}
>>               if(j==5){
>>               f += FIXED_1;}
>>               s=1;
>>               break;
>>           }
>>           }
>>  
>>           if(s==0)
>>           {
>>
>>           if(k < 6)
>>              {
>>               k++;
>>               j = k-1;
>>               uidArray[j] = p->uid;
>>               if(j==1){
>>               b += FIXED_1;}
>>               if(j==2){
>>               c += FIXED_1;}
>>               if(j==3){
>>               d += FIXED_1;}
>>               if(j==4){
>>               e += FIXED_1;}
>>               if(j==5){
>>               f += FIXED_1;}
>>              }
>>              
>>
>>           }
>>
>>       s=0;
>>         }
>>      
>>       i++;
>>  
>>   }
>>
>>   }
>>          
>>   read_unlock(&tasklist_lock);
>>   return nr;
>>
>>}
>>
>>unsigned long avenrun[6];
>>
>>unsigned long avenrunT;
>>
>>static inline void calc_load(unsigned long ticks)
>>{
>>   unsigned long active_tasks;  /*fixed-point */
>>   static int count = LOAD_FREQ;
>>
>>   count -= ticks;
>>   if (count < 0) {
>>       count += LOAD_FREQ;
>>       active_tasks = count_active_tasks();
>>
>>       CALC_LOAD(avenrunT, EXP_5, active_tasks);
>>       CALC_LOAD(avenrun[0], EXP_5, a);
>>       CALC_LOAD(avenrun[1], EXP_5, b);
>>       CALC_LOAD(avenrun[2], EXP_5, c);
>>       CALC_LOAD(avenrun[3], EXP_5, d);
>>       CALC_LOAD(avenrun[4], EXP_5, e);
>>       CALC_LOAD(avenrun[5], EXP_5, f);
>>      
>>   }
>>}
>>
>>I have updated all the other places(all .h and .c files) to suit this code.
>>
>>And the result is stored in    proc/loadavg as
>>
>>       0.21   0.21   100   0.00     0       0.00      0        0.00     
>>0        0.00     0            0.00        0
>>         T        a 1      uid     b1    500        c 1     501      d1 
>>    502      e1      503          f1         504
>>
>>T- for totall
>>a1- root or uid < 500
>>b1,c1,di etc for uid>=500
>>
>>In this perticular case I have login as root so that uid 100 is seen. 
>>There is no 500 or above. they are all 0.
>>
>>But even if I start login remotely those processors started through 
>>telnet inherits uid <500. Then they will be shown under a1
>>
>>I get uids from task_struct
>>
>>Thanks
>>Sena Seneviratne
>>Computer Engineering Lab
>>School of Electrical and Information Engineering
>>Sydney University
>>
>>-
>>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>>the body of a message to majordomo@vger.kernel.org
>>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>Please read the FAQ at  http://www.tux.org/lkml/
>>    
>>
>
>  
>




^ permalink raw reply	[flat|nested] 5+ messages in thread

* task_struct and uid of a task
@ 2003-12-30 20:06 sena
       [not found] ` <20031231124528.GA2837@lnx-holt>
  0 siblings, 1 reply; 5+ messages in thread
From: sena @ 2003-12-30 20:06 UTC (permalink / raw)
  To: rusty; +Cc: linux-kernel

Dear Rusty,

Thank you for your previous reply. I feel like you would be able to 
assist me.

Say a computer has 5 user logins name1(500), name2(501), 
name3(502).........name5(504) apart from root. If these 5 people 
remotely login and runs there jobs, then the user name of those jobs are 
name1,name2 and name3.

Say if they use telnet to remotely login then those Tasks will be 
started under telnet server as children.

As the children inherits uid, euid etc of the parents. That means telnet 
is run as root and it inherits uid<500.

task_struct has uid and it is updated accordingly.


I have built the kernel 2.4.19sena1 successfully but this is my problem. 
The problem because child process inherits uid etc if I start any 
process through telnet

My code is as follows:

unsigned long a; //for root uid<500, I am getting this uidArray[0] is 
for storing uid (assumed 100 for all <500)
unsigned long b; //for 500
unsigned long c; //for 501
unsigned long d; //for 502
unsigned long e; //for 503
unsigned long f; // for 504

unsigned int uidArray[7];

static unsigned long count_active_tasks(void)
{
    struct task_struct *p;
    unsigned long nr = 0;

    int s = 0;
   
    int i=0;
    int j=0;
    int k=0;
    int m=0;

    a=b=c=d=e=f=0;
   
       read_lock(&tasklist_lock);

    for_each_task(p)
    {
        if ((p->state == TASK_RUNNING ||
             (p->state & TASK_UNINTERRUPTIBLE)))
    {

        nr += FIXED_1; //nr total tasks
       
        if(i==0)
        {
            uidArray[0] = 100;

            if(p->uid < 500)
            {
           
            a += FIXED_1;
            }
            else
            {
            uidArray[1] = p->uid;
            b += FIXED_1;
            k++;
            }
         k++;
        }
        else
        {
           for(j=0; j < k ; j++)
           {
               
            if((j==0)&& (p->uid < 500) && (s==0))
            {
                a += FIXED_1;
                s = 1;
                break;
            }
            else if((uidArray[j] == p->uid) && s==0)
            {
                if(j==1){
                b += FIXED_1;}
                if(j==2){
                c += FIXED_1;}
                if(j==3){
                d += FIXED_1;}
                if(j==4){
                e += FIXED_1;}
                if(j==5){
                f += FIXED_1;}
                s=1;
                break;
            }
            }
   
            if(s==0)
            {

            if(k < 6)
               {
                k++;
                j = k-1;
                uidArray[j] = p->uid;
                if(j==1){
                b += FIXED_1;}
                if(j==2){
                c += FIXED_1;}
                if(j==3){
                d += FIXED_1;}
                if(j==4){
                e += FIXED_1;}
                if(j==5){
                f += FIXED_1;}
               }
               

            }

        s=0;
          }
       
        i++;
   
    }

    }
           
    read_unlock(&tasklist_lock);
    return nr;

}

unsigned long avenrun[6];

unsigned long avenrunT;

static inline void calc_load(unsigned long ticks)
{
    unsigned long active_tasks;  /*fixed-point */
    static int count = LOAD_FREQ;

    count -= ticks;
    if (count < 0) {
        count += LOAD_FREQ;
        active_tasks = count_active_tasks();

        CALC_LOAD(avenrunT, EXP_5, active_tasks);
        CALC_LOAD(avenrun[0], EXP_5, a);
        CALC_LOAD(avenrun[1], EXP_5, b);
        CALC_LOAD(avenrun[2], EXP_5, c);
        CALC_LOAD(avenrun[3], EXP_5, d);
        CALC_LOAD(avenrun[4], EXP_5, e);
        CALC_LOAD(avenrun[5], EXP_5, f);
       
    }
}

I have updated all the other places(all .h and .c files) to suit this code.

And the result is stored in    proc/loadavg as

        0.21   0.21   100   0.00     0       0.00      0        0.00     
0        0.00     0            0.00        0
          T        a 1      uid     b1    500        c 1     501      d1 
     502      e1      503          f1         504

T- for totall
a1- root or uid < 500
b1,c1,di etc for uid>=500

In this perticular case I have login as root so that uid 100 is seen. 
There is no 500 or above. they are all 0.

But even if I start login remotely those processors started through 
telnet inherits uid <500. Then they will be shown under a1

I get uids from task_struct

Thanks
Sena Seneviratne
Computer Engineering Lab
School of Electrical and Information Engineering
Sydney University


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-01-05  3:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-31  5:13 task_struct and uid of a task auntvini
2003-12-31  6:15 ` Rusty Russell
  -- strict thread matches above, loose matches on Subject: below --
2003-12-30 20:06 sena
     [not found] ` <20031231124528.GA2837@lnx-holt>
2004-01-04 14:34   ` sena
2004-01-04 15:19   ` sena

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).