Posted on December 27, 2006 by awmanoj
There are numbers from 1 to N in an array. out of these, one of the number gets duplicated and one is missing. The task is to write a program to find out the duplicate number. Conditions: you have to do it in O(n) time without using any auxilary space (array, bitsets, maps etc..)
I tried [...]
Filed under: Uncategorized | Leave a Comment »
Posted on December 22, 2006 by awmanoj
We can verify a user space address while executing in kernel by using the following function
int access_ok(int type, const void *addr, unsigned long size);
Defined in <asm/uaccess.h>, this function returns 1 if the address addr is a user space address and 0 if its a kernel space address (talking of the virtual address of course). argument [...]
Filed under: linux, linux kernel, technical | Leave a Comment »
Posted on December 13, 2006 by awmanoj
Slab Poisoning is a term popular among linux kernel hackers and refers to the condition caused by using an uninitialized dynamically allocated memory location, mostly a panic (or oops).
How to find if you have a slab poisoning ?
If you have an offending address 0xa5a5a5a5 somewhere in the kernel oops message, you can be almost be [...]
Filed under: linux, linux kernel, technical | Leave a Comment »
Posted on December 8, 2006 by awmanoj
As a part of understanding the scheduling of kernel thread in linux, I wrote following module code.
#include <linux/module.h>
#include <linux/kernel.h>
#define DBG_FN_ENTRY() \
do { \
printk(KERN_INFO “Inside function [ %s ]\n”, \
__FUNCTION__); \
} while(0)
struct task_struct *sleeping_task = NULL;
int k = 0;
int func(void *s)
{
int i;
for(i=0;i<20;i++) {
printk(“[%d][%s]\n”, i, (char *)s);
if(sleeping_task)
wake_up_process(sleeping_task);
if(i==10) {
sleeping_task = current;
set_current_state(TASK_INTERRUPTIBLE);
schedule();
}
}
}
int init_module(void)
{
DBG_FN_ENTRY();
kernel_thread(func, (void *)”first”, 0);
kernel_thread(func, (void *)”second”, 0);
return [...]
Filed under: linux, linux kernel, technical | Leave a Comment »
Posted on December 6, 2006 by awmanoj
Few days back, I had to find the MAC address of a machine whose IP address I know. Simple solution is to use ARP but the question is how ? One solution that I have is ping the machine and check your ARP cache. e.g. you need to find out the MAC address of [...]
Filed under: linux, networking, technical | 2 Comments »
Posted on December 4, 2006 by awmanoj
A friend of mine was asked to write the following program in an interview. He asked me how to do it?
Write a program to reverse the order of the words in a given statement (string). e.g. if input string is “India is a great country”, Output should be “country great a is India”.
This is [...]
Filed under: Programming, technical | 2 Comments »
Posted on December 3, 2006 by awmanoj
Just got hold of this code from a C programming resource. C really makes a good language for obfuscated code – valid programs which ‘look’ crap !
#include >stdio.h<
main(t,_,a)
char *a;
{return!0<t?t<3?main(-79,-13,a+main(-87,1-_,
main(-86, 0, a+1 )+a)):1,t<_?main(t+1, _, a ):3,main ( -94, -27+t, a
)&&t == 2 ?_<13 ?main ( 2, _+1, “%s %d %d\n” ):9:16:t<0?t<-72?main(_,
t,”@n’+,#’/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+\
,/+#n+,/#;#q#n+,/+k#;*+,/’r :’d*’3,}{w+K w’K:’+}e#’;dq#’l q#’+d’K#!/\
+k#;q#’r}eKK#}w’r}eKK{nl]’/#;#q#n’){)#}w’){){nl]’/+#n’;d}rw’ i;# ){n\
l]!/n{n#’; [...]
Filed under: Programming, linux, technical | Leave a Comment »
Posted on December 1, 2006 by awmanoj
I came to know about this growing plantations company in south india. Its a part of the reputed RPG group. Following are few good words by Roshan :-
It owns large plantations in South India, is part of the RPG group. South india is where I see property prices zooming in the future- it’s far safer [...]
Filed under: business, investing | Leave a Comment »