>How to install Flashplayer in Firefox on Linux?

>Firefox on Linux needs manual installation of Flash player. Surprisingly it’s bit messy, so here are a few steps to accomplish this task:

– Get the rpm/deb package downloaded on your system(typically titled adobe-release-i386-1.0-1.noarch.rpm/ flash-plugin-10.0.22.87-release.i386.rpm).

– Install with YUM/aptget like follows:
$yum install adobe-release-i386-1.0-1.noarch.rpm

– Open Firefox browser, and in the address bar type “about:config”.
If you see flash player entry in there, you are fine. Else, go to next step.

– Run $updatedb
It’ll update the database for “locate” command.

– Run $locate libflashplayer
Most probably it will tell you the directory, “/usr/lib/flash-plugin” directory. Here you will find libflashplayer.so.

– Copy “libflashplayer.so” to Firefox installation directory (e.g. “/usr/local/bin/firefox/plugins/”). Also copy it to “/usr/lib”. This will make this library available to all users.

– Again check your Firefox browser with “about:config”. You should see a couple of flash player entries there.

That’s all. Try running Youtube for verification:-)

Ref: http://www.linuxquestions.org/questions/linux-software-2/how-to-install-flashplayer-in-firefox-487406/


Windows flavor in Linux: YUM

Linux is bad for naïve users especially while installing new software. You always see some dependency missing and all. That’s what I used to think. But no more. Linux has given a break from messy-dirty way of installing a software to a very clean and simple way.

Yes, it’s by Fedora 9(New name for good old Redhat), and it’s called YUM.
Yum makes installing new RPM(Redhat Packet Manager) butter smooth and a slightly simpler than Windows.
All Yum demands is an Internet connection and lo, you are done. Just download your desired RPM and specify it to yum like this:

$yum install my.rpm

After asking you for a ‘YES’, it will take care of everything.

Simple right!


>Idiotic scanf() : Scanning whitespaces in a string

>In C, a few functions are real nasty and scanf() is one of them. It’s specially bad for inputting strings.
What will happen if you give a string:

-> scanf(“%s”, string)

-> Input: “C is stupid”.

Well, you will have only “C” in the “string”.

Reason: It happens because scanf() considers white-spaces as delimiter. So “C” being followed by a white space is considered as the only input. Simple, isn’t it?

Remedy: We have something like follows:

int main()
{
char arr[10];
scanf(“%*[ \t\n]%s”, arr);
puts(arr);
}

IT DOESN’T WORK!!!

Only way is this:

#define SIZE 128

int main() {
char arr[SIZE];
char ch;
int index = 0;

while(ch != ‘\n’ && index < SIZE)
{
ch = getchar();
arr[index] = ch;
index++;
}
arr[index] = ”;
}

Done!


>GNU gdb: The toolbox of commands

>Many a times application throws signals during its execution. By default gdb has some setting for all UNIX defined signals. If this default is “stop” the application, it becomes quite irritating.
To handle a signal: (gdb) handle SIGUSR1 nostop
All available options are:
nostop
GDB should not stop your program when this signal happens. It may still print a message telling you that the signal has come in.

stop
GDB should stop your program when this signal happens. This implies the print keyword as well.

pass
noignore
GDB should allow your program to see this signal; your program can handle the signal, or else it may terminate if the signal is fatal and not handled. pass and noignore are synonyms.

nopass
ignore
GDB should not allow your program to see this signal. nopass and ignore are synonyms.

(Ref: http://sources.redhat.com/gdb/current/onlinedocs/gdb_6.html#SEC44)



>Linux Scheduling: A Few Facts

>- Linux scheduler favors I/O bound processes. It uses dynamic priorities to schedule processes. So a process that has not got CPU for a long time, would get its priority increased and vice verse.

– Processes are moved to different queues and al processes on ready queue are assigned an ‘epoch’. The epoch is relevant for processes in ready queue only.

– Now each process is assigned a quantum which is the CPU time allotted to a process. If a process is blocked, it does not use its quantum and unused quantum is carry forward to next epoch. An epoch completes as soon as all processes in ready queue complete their quantum.

– Dynamic priority(“goodness”) of a process is calculated by base priority and quantum. Hence a I/O bound process which is blocked for a long time, gets its priority improved every time it saves its quantum while it was blocked.


Linux Tips

Changing Linux root password
http://www.paulspoerry.com/2008/09/06/replace-linux-root-password/

Ways of saying ‘Hello! World’ : http://www.fitzrovian.com/hello.html

– sizeof (type) requires parenthese, while sizeof expression
does not.

– How to easily read a declaration from left to right:
transform function argument types from inside out first
move the base type to the end
add outer parentheses if there’s an initial *
change every (*…) to … ->
one -> for each *
move qualifiers, so * const becomes const ->

Example: const int *(**const x [])()

*(**const x [])() const int base type to end
(*(**const x [])()) const int add outer parens
(**const x [])() -> const int remove outer ()
x [] const -> -> () -> const int remove inner ()

array of constant pointers to pointers to functions
returning pointers to constant ints

– p + 1 == &p [1]


Unfolding 2-D array in C

Last weekend my friends and I had a discussion on 2-D array in C. Surprisingly it went long as everyone had some points and knowledge to share 🙂 Finally we could gather some important information and understood this pearl of C better.

I’ll clear this idea with C code snippets.

// Declare an array
int arr[2][3]= {1,2,3,4,5,6};

It’s size is 2*3*sizeof(int) = 24 bytes (Intel x86)

okay, now what will get printed for following statements:
// Say starting address is 1024

o) print &a + 1
o) print a + 1
o) print *a + 1

To answer these questions better, I’ll explain what exactly is a 2-D array. When we declare and define a 2-D array, it’s like a new user defined type to C. It’s a pointer to a memory location that contiguously contains storage of 6 integers. Logically it’s like holding many 1-D array in a followed by one-another.

Ans 1: When you say ‘&a’ , it implies address of user defined type and it’s 1024. Now incrementing it by 1 means moving the pointer by the size of this type which is 24 bytes. Thus it’ll print 1048.

Ans 2: ‘a’ fetch us address of 1-D array or 0th row of our matrix. a+1 would get us address of next row i.e. 1024 + (3*4) = 1036

Ans 3: ‘*a’ would get you the 0th element of 0th row which is 1. So *a + 1 would get us 2.


More Linux Tips

– Detailed info about system: Actually these are kernel messages and are stored as logs in /bin/dmesg.
  – $dmesg

– Determining runlevel {Shows previous & current runlevel}
  $runlevel
  0->Halt 1->Single User Mode
  2-> Multiuser w/o NFS 3-> Full Multiuser 6-> Reboot

– To modify init level-> /etc/inittab

– To switch runlevels, use init command.
`$init 3`

– Difference between Paging and Swapping
Paging refers to movement of pages to frames on the disk. It’s a considerably cheaper operation. Swapping means to move entire address space of a process to disk. This is very expensive operation and happens when a process sleeps or when thrashing occurs.


>Linux Linker Unveiled: The Secret Services

>Linux linker does not seem to be a lead actor in play of application. But it work like the script which is essential to success of the play. Linker(ldd) is a piece of software that is primarily responsible for address patching a.k.a. relocation. Object files bear absolute and relative addresses.

// test.c
int main()
{
foo();
}

Disassembly of section .text:

00000000 :
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 ec 08 sub $0x8,%esp
6: 83 e4 f0 and $0xfffffff0,%esp
9: b8 00 00 00 00 mov $0x0,%eax
e: 29 c4 sub %eax,%esp
10: e8 fc ff ff ff call 11
15: c9 leave
16: c3 ret

# An object file always starts on address 0x0000.

You can see that addresses are relative to the module and called function is completely unknown to foo. Linker take these object files, relocate their addresses to loading addresses(virtual addresses) and resolve calls to function by a function offset table.

To get a function offset table:
$objdump -x ./test.o

RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
00000011 R_386_PC32 foo

All functions called from a file are listed in this table and here foo() has got 0x11 offset. Once all object files are there linker patches the offset with virtual address. Though call to foo() has been patched with correct virtual address, offset of the instruction is still the same(main+0x11).

08048344 :
8048344: 55 push %ebp
8048345: 89 e5 mov %esp,%ebp
8048347: 83 ec 08 sub $0x8,%esp
804834a: 83 e4 f0 and $0xfffffff0,%esp
804834d: b8 00 00 00 00 mov $0x0,%eax
8048352: 29 c4 sub %eax,%esp
8048354: e8 03 00 00 00 call 804835c
8048359: c9 leave
804835a: c3 ret
804835b: 90 nop

0804835c :
804835c: 55 push %ebp
804835d: 89 e5 mov %esp,%ebp
804835f: 5d pop %ebp
8048360: c3 ret