How to access static variable in kernel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




hello all,
                   I am facing a very minor problem which is interesting
also...I am explaining the scenario....

1 fime in kernel lets say ip.c is there....

file name - ip.c
----------------------
main( )
{
..................
.................
static int count = 0;
printk(KERN_DEBUG " value of count = %d\n",count);
if(count == 0)
{
     x = y;
     a = b;
     count++;
}
.................................
.................................
} /*end of main*/
NOTE:- BOLD LETTERS IN THE ABOVE EXAMPLE IS MY ADDED PORTION IN THE
EXISTING FILE ip.c


I want to send lets say 10 packets from transmitter to receiver.
My problem is in the kernel file ip.c I have defined one static int counter
count ..
I want the portion inside the if loop should execute only & only once when
I will start sending packets...
so when I start sending packets the printf will print count == 0 for the
1st packet & for nect packets it will print 1,1,1 as its static.

now if I will stop my transmitter & again if I want to send same 10 packets
, that time the value of count in the 1st packet itself shows count = 1, so
the portion inside the if loop will not get executed..

I want whenever I will start transmitting the value of count should be 0
for the first packets i.e the if loop should execute only once at the
beginning ...HOW IS IT POSSIBLE ????HOW THE COUNT WILL BE ZERO ONCE I WILL
STOP MY APPLICATION ????PLEASE SUGGEST ME..



This same thing works perfectly in application level..whenever I will start
running my program value of count is getting initialized to zero for the
first time..but in kernel why the value is retained all teh time ...

THE ONLY THING IS ALL THE TIME I HAVE TO REBOOT THE KERNEL
ITSELF....WITHOUT REBOOTING HOW IS IT POSSIBLE???
please guide me in this issue??

regards
debarchan
s/w engineer....
















--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux