Linux is bad for naive 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 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!
Friday, May 29, 2009
Thursday, May 21, 2009
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] = '\0';
}
Done!
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] = '\0';
}
Done!
Wednesday, April 15, 2009
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)
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)
Ruby on Rails
Bored of J2EE? I came across a new web app development framework called Ruby on Rails. Based on Agile development philosophy, it's one of the most popular web framework today.
As name suggests, it let's you develop your web application faster and conveniently. All you need to know Ruby before getting started.
Check out more at: http://rubyonrails.org/
As name suggests, it let's you develop your web application faster and conveniently. All you need to know Ruby before getting started.
Check out more at: http://rubyonrails.org/
Tuesday, March 17, 2009
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.
- 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.
Subscribe to:
Posts (Atom)