There are many type of lock and each of them have their own utility. If you can sleep, semaphore is probably what you'll use. Example: static DECLARE_MUTEX(m); down(&m); /* accessing your global structure */ up(&m); There are more than theses 2 methods to work with semaphore. Look at the source. You can look for spin lock too. Spin lock are use often used in ISR because they dont sleep. However, they are cpu consuming so be careful when you hold a spin lock to hold it as short as possible. On July 1, 2004 02:29 pm, Greg Nate wrote: > Regarding acquiring a lock: I realize this may be a stupid question, > but how does one go about doing this? Can you provide a short code > example? > > Thanks > > -----Original Message----- > From: kernelnewbies-bounce@nl.linux.org > [mailto:kernelnewbies-bounce@nl.linux.org]On Behalf Of Dhiman, Gaurav > Sent: Thursday, July 01, 2004 9:27 AM > To: Anupam Kapoor; manish regmi > Cc: so_usp@yahoo.com.br; kernelnewbies@nl.linux.org > Subject: RE: List of Processes > > > > We need to acquire lock before accessing any common data structure of > kernel. As the "task_struct" list is the common data structure of kernel > which is accessed from different places in kernel. > We need to acquire the lock for this task list before accessing it, so > that when we are accessing the list no other process context or kernel > thread should be able to access it. > > Regards, > Gaurav > > > -----Original Message----- > From: kernelnewbies-bounce@nl.linux.org > [mailto:kernelnewbies-bounce@nl.linux.org] On Behalf Of Anupam Kapoor > Sent: Thursday, July 01, 2004 3:18 PM > To: manish regmi > Cc: so_usp@yahoo.com.br; kernelnewbies@nl.linux.org > Subject: Re: List of Processes > > one small doubt, shouldn't we be acquiring a lock while iterating over > all the tasks ? > > anupam > > On Thu, 01 Jul 2004 07:20:25 +0000, manish regmi > > <manish_regmi@hotmail.com> wrote: > > >>iirc there is a macro defined already "for_each_process" that you > > can > > > >use to get all the processes > > > > > >struct task_struct *p; > > > > > >for_each_process (p) { > > > .... > > >} > > > > > >hth > > >kind regards > > >anupam > > > > /* sched.h */ > > > > for_each_task(p){ > > ... > > } > > > > :) > > : > > > > Hi.... > > > > > > > > I would like to know which file i can find the struct > > > > that list all processes executing in linux... > > > > > > > > Thanks, > > > > Luis Henrique. > > > > for_each_task(p) > > { > > ... > > } > > > > You will each task's descriptor on p on each loop. The first one will > > be > > > that of init. You will automatically break from loop when you finish > > traverse through all tasks. > > Actually a circular list. > > > > #define for_each_task(p) \ > > for (p = &init_task ; (p = p->next_task) != &init_task ; ) > > > > regards manish > > > > _________________________________________________________________ > > Add photos to your messages with MSN 8. Get 2 months FREE*. > > http://join.msn.com/?page=features/featuredemail > > -- > Kernelnewbies: Help each other learn about the Linux kernel. > Archive: http://mail.nl.linux.org/kernelnewbies/ > FAQ: http://kernelnewbies.org/faq/ > > > > -- > Kernelnewbies: Help each other learn about the Linux kernel. > Archive: http://mail.nl.linux.org/kernelnewbies/ > FAQ: http://kernelnewbies.org/faq/ > > -- > Kernelnewbies: Help each other learn about the Linux kernel. > Archive: http://mail.nl.linux.org/kernelnewbies/ > FAQ: http://kernelnewbies.org/faq/ -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/