On Wed, Aug 14, 2002 at 02:27:59PM +0530, Debarchan.Dash@lntinfotech.com wrote: > > 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 Note: there is nothing like bold letters in plain text. > 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 ... It works the same way in kernel. Whenever you reboot, the count is zero again (if it's in module, it reduces to whenever you reload the module). > 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?? If you have to run code once a device is opened, you have to put it in open method for that device. Or you can add some data to the device file structure and use that to decide when the code should be run. Everything of course depends on what it means to "start transmitting". It DOES NOT mean to "start your application", because when it's starting, kernel can't know it's "THE YOUR application". But the application sure needs to tell kernel it want's to transmit. It means to open something, that ends up being identified by file descriptor (socket, file, device... it does not matter for the purpose). And opening any such thing leads to open method for given object being called in kernel. And, more importantly, it's the driver of your interest that provides that method. So you must run the code there or you must init a flag associated with given file there and use that later. Oh, there is NO FILE named ip.c in kernel source tree (2.4.18). And there can't be symbol "main" defined in any of the drivers. In fact, there is no symbol main at all acoording to nm on an uncompressed kernel image. ------------------------------------------------------------------------------- Jan 'Bulb' Hudec <bulb@ucw.cz> -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/