Friday, March 30, 2012

Troubleshooting Linux with syslog

Source: http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch05_:_Troubleshooting_Linux_with_syslog

Contents

Introduction

There are hundreds of Linux applications on the market, each with their own configuration files and help pages. This variety makes Linux vibrant, but it also makes Linux system administration daunting. Fortunately, in most cases, Linux applications use the syslog utility to export all their errors and status messages to files located in the /var/log directory.
This can be invaluable in correlating the timing and causes of related events on your system. It is also important to know that applications frequently don't display errors on the screen, but will usually log them somewhere. Knowing the precise message that accompanies an error can be vital in researching malfunctions in product manuals, online documentation, and Web searches.
syslog, and the logrotate utility that cleans up log files, are both relatively easy to configure but they frequently don't get their fair share of coverage in most texts. I've included syslog here as a dedicated chapter to both emphasize its importance to your Linux knowledge and prepare you with a valuable skill that will help you troubleshoot all the Linux various applications that will be presented throughout the book

syslog

syslog is a utility for tracking and logging all manner of system messages from the merely informational to the extremely critical. Each system message sent to the syslog server has two descriptive labels associated with it that makes the message easier to handle.
  • The first describes the function (facility) of the application that generated it. For example, applications such as mail and cron generate messages with easily identifiable facilities named mail and cron.
  • The second describes the degree of severity of the message. There are eight in all and they are listed in Table 5-1:
You can configure syslog's /etc/rsyslog.conf configuration file to place messages of differing severities and facilities in different files. This procedure will be covered next.


Table 5-1 Syslog Facilities

Severity Level Keyword Description
0 emergencies System unusable
1 alerts Immediate action required
2 critical Critical condition
3 errors Error conditions
4 warnings Warning conditions
5 notifications Normal but significant conditions
6 informational Informational messages
7 debugging Debugging messages

The /etc/rsyslog.conf File

The files to which syslog writes each type of message received is set in the /etc/rsyslog.conf configuration file. In older versions of Fedora this file was named /etc/syslog.conf.
This file consists of two columns. The first lists the facilities and severities of messages to expect and the second lists the files to which they should be logged. By default, RedHat/Fedora's /etc/rsyslog.conf file is configured to put most of the messages in the file /var/log/messages. Here is a sample:
*.info;mail.none;authpriv.none;cron.none           /var/log/messages
In this case, all messages of severity "info" and above are logged, but none from the mail, cron or authentication facilities/subsystems. You can make this logging even more sensitive by replacing the line above with one that captures all messages from debug severity and above in the /var/log/messages file. This example may be more suitable for troubleshooting.
*.debug                                          /var/log/messages
In this example, all debug severity messages; except auth, authpriv, news and mail; are logged to the /var/log/debug file in caching mode. Notice how you can spread the configuration syntax across several lines using the slash (\) symbol at the end of each line.
*.=debug;\
       auth,authpriv.none;\
       news.none;mail.none     -/var/log/debug
Here we see the /var/log/messages file configured in caching mode to receive only info, notice and warning messages except for the auth, authpriv, news and mail facilities.
*.=info;*.=notice;*.=warn;\
       auth,authpriv.none;\
       cron,daemon.none;\
       mail,news.none          -/var/log/messages
You can even have certain types of messages sent to the screen of all logged in users. In this example messages of severity emergency and above triggers this type of notification. The file definition is simply replaced by an asterisk to make this occur.
*.emerg                         *
Certain applications will additionally log to their own application specific log files and directories independent of the syslog.conf file. Here are some common examples:
Files:
/var/log/maillog             : Mail
/var/log/httpd/access_log    : Apache web server page access logs
Directories:
/var/log
/var/log/samba                      : Samba messages
/var/log/mrtg                       : MRTG messages
/var/log/httpd                      : Apache webserver messages
Note: In some older versions of Linux the /etc/rsyslog.conf file was very sensitive to spaces and would recognize only tabs. The use of spaces in the file would cause unpredictable results. Check the formatting of your /etc/rsyslog.conf file to be safe.

Activating Changes to the syslog Configuration File

Changes to /etc/rsyslog.conf will not take effect until you restart syslog. Issue these command to do so :
Systems using systemd:
[root@bigboy tmp]# systemctl restart rsyslog.service
Systems using sysvinit:
[root@bigboy tmp]# service rsyslog restart
In older versions of Fedora, this would be:
[root@bigboy tmp]# service syslog restart

How to View New Log Entries as They Happen

If you want to get new log entries to scroll on the screen as they occur, then you can use this command:
[root@bigboy tmp]# tail -f /var/log/messages
Similar commands can be applied to all log files. This is probably one of the best troubleshooting tools available in Linux. Another good command to use apart from tail is grep. grep will help you search for all occurrences of a string in a log file; you can pipe it through the more command so that you only get one screen at a time. Here is an example:
[root@bigboy tmp]# grep string /var/log/messages | more
You can also just use the plain old more command to see one screen at a time of the entire log file without filtering with grep. Here is an example:
[root@bigboy tmp]# more /var/log/messages


Logging syslog Messages to a Remote Linux Server

Logging your system messages to a remote server is a good security practice. With all servers logging to a central syslog server, it becomes easier to correlate events across your company. It also makes covering up mistakes or malicious activities harder because the purposeful deletion of log files on a server cannot simultaneously occur on your logging server, especially if you restrict the user access to the logging server.


Configuring the Linux Syslog Server

By default syslog doesn't expect to receive messages from remote clients. Here's how to configure your Linux server to start listening for these messages.
As we saw previously, syslog checks its /etc/rsyslog.conf file to determine the expected names and locations of the log files it should create. It also checks the file /etc/sysconfig/syslog to determine the various modes in which it should operate. Syslog will not listen for remote messages unless the SYSLOGD_OPTIONS variable in this file has a -r included in it as shown below.
# Options to syslogd
# -m 0 disables 'MARK' messages.
# -r enables logging from remote machines
# -x disables DNS lookups on messages received with -r
# See syslogd(8) for more details

 SYSLOGD_OPTIONS="-m 0 -r"

# Options to klogd
# -2 prints all kernel oops messages twice; once for klogd to decode, and
#    once for processing with 'ksymoops'
# -x disables all klogd processing of oops messages entirely
# See klogd(8) for more details

KLOGD_OPTIONS="-2"
Note: In Debian / Ubuntu systems you have to edit the syslog startup script /etc/init.d/sysklogd directly and make the SYSLOGD variable definition become "-r".
# Options for start/restart the daemons
#   For remote UDP logging use SYSLOGD="-r"
#
#SYSLOGD="-u syslog"
SYSLOGD="-r"
You will have to restart syslog on the server for the changes to take effect. The server will now start to listen on UDP port 514, which you can verify using either one of the following netstat command variations.
[root@bigboy tmp]# netstat -a | grep syslog
udp        0      0 *:syslog                *:*
[root@bigboy tmp]# netstat -an | grep 514
udp        0      0 0.0.0.0:514             0.0.0.0:*
[root@bigboy tmp]#

Configuring the Linux Client

The syslog server is now expecting to receive syslog messages. You have to configure your remote Linux client to send messages to it. This is done by editing the /etc/hosts file on the Linux client named smallfry. Here are the steps:
1) Determine the IP address and fully qualified hostname of your remote logging host.
2) Add an entry in the /etc/hosts file in the format:
IP-address    fully-qualified-domain-name    hostname    "loghost"
Example:
192.168.1.100    bigboy.my-site.com    bigboy     loghost
Now your /etc/hosts file has a nickname of "loghost" for server bigboy.
3) The next thing you need to do is edit your /etc/rsyslog.conf file to make the syslog messages get sent to your new loghost nickname.
*.debug                                       @loghost
*.debug                                       /var/log/messages
You have now configured all debug messages and higher to be logged to both server bigboy ("loghost") and the local file /var/log/messages. Remember to restart syslog to get the remote logging started.
You can now test to make sure that the syslog server is receiving the messages with a simple test such as restarting the lpd printer daemon and making sure the remote server sees the messages.
Linux Client
[root@smallfry tmp]# service lpd restart
Stopping lpd: [  OK  ]
Starting lpd: [  OK  ]
[root@smallfry tmp]#
Linux Server
[root@bigboy tmp]# tail /var/log/messages
...
...
Apr 11 22:09:35 smallfry lpd: lpd shutdown succeeded
Apr 11 22:09:39 smallfry lpd: lpd startup succeeded
...
...
[root@bigboy tmp]#

Syslog Configuration and Cisco Network Devices

syslog reserves facilities "local0" through "local7" for log messages received from remote servers and network devices. Routers, switches, firewalls and load balancers each logging with a different facility can each have their own log files for easy troubleshooting. Appendix 4 has examples of how to configure syslog to do this with Cisco devices using separate log files for the routers, switches, PIX firewalls, CSS load balancers and LocalDirectors.


Logrotate

The Linux utility logrotate renames and reuses system error log files on a periodic basis so that they don't occupy excessive disk space.


The /etc/logrotate.conf File

This is logrotate's general configuration file in which you can specify the frequency with which the files are reused.
  • You can specify either a weekly or daily rotation parameter. In the case below the weekly option is commented out with a #, allowing for daily updates.
  • The rotate parameter specifies the number of copies of log files logrotate will maintain. In the case below the 4 copy option is commented out with a #, while allowing 7 copies.
  • The create parameter creates a new log file after each rotation
Therefore, our sample configuration file will create daily archives of all the logfiles and store them for seven days. The files will have the following names with, logfile being current active version:
logfile
logfile.0
logfile.1
logfile.2
logfile.3
logfile.4
logfile.5
logfile.6


Sample Contents of /etc/logrotate.conf

# rotate log files weekly
#weekly

# rotate log files daily
daily

# keep 4 weeks worth of backlogs
#rotate 4

# keep 7 days worth of backlogs
rotate 7

# create new (empty) log files after rotating old ones
create


The /etc/logrotate.d Directory

Most Linux applications that use syslog will put an additional configuration file in this directory to specify the names of the log files to be rotated. It is a good practice to verify that all new applications that you want to use the syslog log have configuration files in this directory. Here are some sample files that define the specific files to be rotated for each application.
Here is an example of a custom file located in this directory that rotates files with the .tgz extension which are located in the /data/backups directory. The parameters in this file will override the global defaults in the /etc/logrotate.conf file. In this case, the rotated files won't be compressed, they'll be held for 30 days only if they are not empty, and they will be given file permissions of 600 for user root.
/data/backups/*.tgz {

   daily
   rotate 30
   nocompress
   missingok
   notifempty
   create 0600 root root
}

Note: In Debian / Ubuntu systems the /etc/cron.daily/sysklogd script reads the /etc/rsyslog.conf file and rotates any log files it finds configured there. This eliminates the need to create log rotation configuration files for the common system log files in the /etc/logrotate.d directory. As the script resides in the /etc/cron.daily directory it automatically runs every 24 hours. In Fedora / Redhat systems this script is replaced by the /etc/cron.daily/logrotate daily script which does not use the contents of the syslog configuration file, relying mostly on the contents of the /etc/logrotate.d directory.

Activating logrotate

The above logrotate settings in the previous section will not take effect until you issue the following command:
[root@bigboy tmp]# logrotate -f
If you want logrotate to reload only a specific configuration file, and not all of them, then issue the logrotate command with just that filename as the argument like this:
[root@bigboy tmp]# logrotate -f /etc/logrotate.d/syslog

Compressing Your Log Files

On busy Web sites the size of your log files can become quite large. Compression can be activated by editing the logrotate.conf file and adding the compress option.
#
# File: /etc/logrotate.conf
#

# Activate log compression

compress
The log files will then start to become archived with the gzip utility, each file having a .gz extension.
[root@bigboy tmp]# ls /var/log/messages*
/var/log/messages      /var/log/messages.1.gz /var/log/messages.2.gz
/var/log/messages.3.gz /var/log/messages.4.gz /var/log/messages.5.gz
/var/log/messages.6.gz /var/log/messages.7.gz
[root@bigboy tmp]#
Viewing the contents of the files still remains easy because the zcat command can quickly output their contents to the screen. Use the command with the compressed file's name as the argument as seen below.
[root@bigboy tmp]# zcat /var/log/messages.1.gz
...
...
Nov 15 04:08:02 bigboy httpd: httpd shutdown succeeded
Nov 15 04:08:04 bigboy httpd: httpd startup succeeded
Nov 15 04:08:05 bigboy sendmail[6003]: iACFMLHZ023165: to=<tvaughan@clematis4spiders.info>,
delay=2+20:45:44, xdelay=00:00:02, mailer=esmtp, pri=6388168,
relay=www.clematis4spiders.info. [222.134.66.34], dsn=4.0.0, 
stat=Deferred: Connection refused by www.clematis4spiders.info.
[root@bigboy tmp]#

syslog-ng

The more recent syslog-ng application combines the features of logrotate and syslog to create a much more customizable and feature rich product. This can be easily seen in the discussion of its configuration file that follows.

The /etc/syslog-ng/syslog-ng.conf file

The main configuration file for syslog-ng is the /etc/syslog-ng/sylog-ng.conf file but only rudimentary help on its keywords can be found using the Linux man pages.
[root@bigboy tmp]# man syslog-ng.conf
Don’t worry, we’ll soon explore how much more flexible syslog-ng can be when compared to regular syslog. 

Simple Server Side Configuration for Remote Clients

Figure 5-1 has a sample syslog-ng.conf file and outlines some key features. The options section that covers global characteristics is fully commented, but it is the source, destination and log sections that define the true strength of the customizability of syslog-ng.


Figure 5-1 A Sample syslog-ng.conf File

options {

          # Number of syslog lines stored in memory before being written to files
          sync (0);

          # Syslog-ng uses queues
          log_fifo_size (1000);

          # Create log directories as needed
          create_dirs (yes);

          # Make the group "logs" own the log files and directories
          group (logs);
          dir_group (logs);

          # Set the file and directory permissions
          perm (0640);
          dir_perm (0750);

          # Check client hostnames for valid DNS characters
          check_hostname (yes);

          # Specify whether to trust hostname in the log message.
          # If "yes", then it is left unchanged, if "no" the server replaces
          # it with client's DNS lookup value.
          keep_hostname (yes);

          # Use DNS fully qualified domain names (FQDN) 
          # for the names of log file folders
          use_fqdn (yes);
          use_dns (yes);

          # Cache DNS entries for up to 1000 hosts for 12 hours
          dns_cache (yes);
          dns_cache_size (1000);
          dns_cache_expire (43200);

        };


# Define all the sources of localhost generated syslog
# messages and label it "d_localhost"
source s_localhost {
          pipe ("/proc/kmsg" log_prefix("kernel: "));
          unix-stream ("/dev/log");
          internal();
};
 
# Define all the sources of network generated syslog
# messages and label it "d_network"
source s_network {
          tcp(max-connections(5000));
          udp();
};

# Define the destination "d_localhost" log directory
destination d_localhost {
           file ("/var/log/syslog-ng/$YEAR.$MONTH.$DAY/localhost/$FACILITY.log");
};

# Define the destination "d_network" log directory
destination d_network {
          file ("/var/log/syslog-ng/$YEAR.$MONTH.$DAY/$HOST/$FACILITY.log");
};

# Any logs that match the "s_localhost" source should be logged
# in the "d_localhost" directory

log { source(s_localhost);
      destination(d_localhost);
};

# Any logs that match the "s_network" source should be logged
# in the "d_network" directory
 
log { source(s_network);
       destination(d_network);
};

In our example, the first set of sources is labeled s_localhost. It includes all system messages sent to the Linux /dev/log device, which is one of syslog's data sources, all messages that syslog-ng views as being of an internal nature and additionally inserts the prefix "kernel" to all messages it intercepts on their way to the /proc/kmsg kernel message file.
Like a regular syslog server which listens for client messages on UDP port 514, syslog-ng also listens on TCP port 514. The second set of sources is labeled s_network and includes all syslog messages obtained from UDP sources and limits TCP syslog connections to 5000. Limiting the number of connections to help regulate system load is a good practice in the event that some syslog client begins to inundate your server with messages.
Our example also has two destinations for syslog messages, one named d_localhost, the other, d_network. These examples show the flexibility of syslog-ng in using variables. The $YEAR, $MONTH and $DAY variables map to the current year, month and day in YYYY, MM and DD format respectively. Therefore the example:
/var/log/syslog-ng/$YEAR.$MONTH.$DAY/$HOST/$FACILITY.log
refers to a directory called /var/log/syslog-ng/2005.07.09 when messages arrive on July 9, 2005. The $HOST variable refers to the hostname of the syslog client and will map to the client's IP address if DNS services are deactivated in the options section of the syslog-ng.conf file. Similarly the $FACILITY variable refers to the facility of the syslog messages that arrive from that host.

Using syslog-ng in Large Data Centers

Figure 5-2 has a sample syslog-ng.conf file snippet that defines some additional features that may be of interest in a data center environment.

Figure 5-2 More Specialized syslog-ng.conf Configuration

options {

          # Number of syslog lines stored in memory before being written to files
          sync (100);
};


# Define all the sources of network generated syslog
# messages and label it "s_network_1"
source s_network_1 {
          udp(ip(192.168.1.201) port(514));
};

# Define all the sources of network generated syslog
# messages and label it "s_network_2"
source s_network_2 {
          udp(ip(192.168.1.202) port(514));
};

# Define the destination "d_network_1" log directory
destination d_network_1 {
          file ("/var/log/syslog-ng/servers/$YEAR.$MONTH.$DAY/$HOST/$FACILITY.log");
};

# Define the destination "d_network_2" log directory
destination d_network_2 {
          file ("/var/log/syslog-ng/network/$YEAR.$MONTH.$DAY/$HOST/$FACILITY.log");
};

# Define the destination "d_network_2B" log directory
destination d_network_2B {
          file ("/var/log/syslog-ng/network/all/network.log");
};

# Any logs that match the "s_network_1" source should be logged
# in the "d_network_1" directory

log { source(s_network_1);
      destination(d_network_1);
};

# Any logs that match the "s_network_2" source should be logged
# in the "d_network_2" directory

log { source(s_network_2);
      destination(d_network_2);
};

# Any logs that match the "s_network_2" source should be logged
# in the "d_network_2B" directory also

log { source(s_network_2);
      destination(d_network_2B);
};
In this case we have configured syslog to:
  1. Listen on IP address 192.168.1.201 as defined in the source s_network_1. Messages arriving at this address will be logged to a subdirectory of /var/log/syslog-ng/servers/ arranged by date as specified by destination d_network_1. As you can guess, this address and directory be used by all servers in the data center.
  2. Listen on IP address 192.168.1.202 as defined in the source s_network_2. Messages arriving at this address will be logged to a subdirectory of /var/log/syslog-ng/network/ arranged by date as specified by d_network_2. This will be the IP address and directory to which network devices would log.
  3. Listen on IP address 192.168.1.202 as defined in the source s_network_2. Messages arriving at this address will also be logged to file /var/log/syslog-ng/all/debug.log as part of destination d_network_2B.This will be a single file to which all network devices would log. Server failures are usually isolated to single servers whereas network failures are more likely to be cascading involving many devices. The advantage of searching a single file is that it makes it easier to determine the exact sequence of events.
  4. As there could be many devices logging to the syslog-ng server, the sync option is set to write data to disk only after receiving 100 syslog messages. Constant receipt of syslog messages can have a significant impact on your system’s disk performance. This option allows you to queue the messages in memory for less frequent disk updates.
Now that you have an understanding of how to configure syslog-ng it’s time to see how you install it.

Installing and Starting syslog-ng

You can install syslog-ng using standard Linux procedures.The syslog-ng and rsyslog packages cannot be installed at the same time. You have to uninstall one in order for the other to work. Here’s how you can install syslog-ng using RPM package files.
1. Uninstall rsyslog using the rpm command. There are some other RPMs that rely on rsyslog so you will have to do this while ignoring any dependencies with the –nodeps flag.
[root@bigboy tmp]# rpm -e --nodeps rsyslog
2. Install syslog-ng using yum.
[root@bigboy tmp]# yum -y install syslog-ng
3. Start the new syslog-ng daemon immediately and make sure it will start on the next reboot.
Systems using sysvinit:
[root@bigboy tmp]# chkconfig syslog-ng on
[root@bigboy tmp]# service syslog-ng start
Starting syslog-ng: [  OK  ]
[root@bigboy tmp]#
Systems using systemd:
[root@bigboy tmp]# systemctl enable syslog-ng.service
[root@bigboy tmp]# systemctl start syslog-ng.service
Starting syslog-ng: [  OK  ]
[root@bigboy tmp]#
Your new syslog-ng package is now up and running and ready to go!

Configuring syslog-ng Clients

Clients logging to the syslog-ng server don't need to have syslog-ng installed on them, a regular syslog client configuration will suffice.
If you are running syslog-ng on clients, then you’ll need to modify your configuration file. Let’s look at Example 5-1 – Syslog-ng Sample Client Configuration.

Example 5-1 - Syslog-ng Sample Client Configuration

source s_sys {
   file ("/proc/kmsg" log_prefix("kernel: "));
   unix-stream ("/dev/log");
   internal();
};

destination loghost { 
   udp("loghost.linuxhomenetworking.com"); 
};

filter notdebug { 
   level(info...emerg); 
};

log { 
   source(local);
   filter(notdebug);
   destination(loghost); 
};
The s_sys source comes default in many syslong-ng.conf files, we have just added some additional parameters to make it work. Here the destination syslog logging server is defined as loghost.linuxhomenetworking.com. We have also added a filter to the log section to make sure only the most urgent messages, info level and above (not debug), get logged to the remote server. After restarting syslong-ng on your client, your syslog server will start receiving messages.

Simple syslog Security

One of the shortcomings of a syslog server is that it doesn't filter out messages from undesirable sources. It is therefore wise to implement the use of TCP wrappers or a firewall to limit the acceptable sources of messages when your server isn't located on a secure network. This will help to limit the effectiveness of syslog based denial of service attacks aimed at filling up your server's hard disk or taxing other system resources that could eventually cause the server to crash.
Remember that regular syslog servers listen on UDP port 514 and syslog-ng servers rely on port 514 for both UDP and TCP. Please refer to Chapter 14, "Linux Firewalls Using iptables", on Linux firewalls for details on how to configure the Linux iptables firewall application and Appendix I, "Miscellaneous Linux Topics", for further information on configuring TCP wrappers.

Conclusion

In the next chapter we cover the installation of Linux applications, and the use of syslog will become increasingly important especially in the troubleshooting of Linux-based firewalls which can be configured to ignore and then log all undesirable packets; the Apache Web server which logs all application programming errors generated by some of the popular scripting languages such as PERL and PHP; and finally, Linux mail whose configuration files are probably the most frequently edited system documents of all and which correspondingly suffer from the most mistakes.
This syslog chapter should make you more confident to learn more about these applications via experimentation because you'll at least know where to look at the first sign of trouble.

Thursday, March 29, 2012

Cách học tiếng Anh hiệu quả nhất?


Author: doremon-nobita
 
"Em đã học tiếng anh từ năm lớp 6 nhưng năm nay đã lớp 11 rồi nhưng tiếng anh của em rất em nhưng em lại thích môn công nghệ thông tin. Em biết rằng môn này cần phải có ngoại ngữ vững chắc và giỏi. Nhưng ngoại ngữ của em thì lại rất kém vậy có ai chỉ em cách nào để ngoại ngữ của em tốt hơn không ạ. Và nếu muốn trở thành 1 người vững vàng trong công nghệ thông tin thì em nên học tiếng anh và công nghệ thông tin cùng 1 lúc hay sao ạ.? " 


Doremon khuyên bạn trước câu này rồi trả lời sau, nếu có muốn lập những topic với nội dung như trên thì nên ghi thêm vài dòng chữ "em đã đọc các topic nói về vấn đề em muốn hỏi, nhưng không một topic nào có giá trị, nay các anh có thể cho em thêm lời khuyên..." để mấy "anh lớn" như anh Kyo-mắt quỷ Kyo khỏi phiền lòng và trả lời "Vui lòng tìm kiếm trước khi hỏi. Các bài viết về vấn đề này đã có quá nhiều"

Bài viết thì nhiều nhưng giá trị không bao nhiêu thì cũng chẳng nên nhiều để làm gì. Mà chẳng có giá trị thì đồng nghĩa với việc người hỏi cần câu trả lời giá trị hơn. Vậy ý nghĩa của những câu nói này là gì? Là topic này sẽ cung cấp cho các bạn câu trả lời giá trị nhất về cách học anh văn, giá trị hơn những gì được cho là giá trị ở nơi này. Rất có thể khi đọc tới đây sẽ có 1 vài người tức giận, nhưng các bạn hãy cứ bình tĩnh và trút cơn giận sau khi đã đọc hết topic này

Thật sự là rất mất thời gian khi phải viết những topic dạng này, nhưng nhiều khi không viết lại không được. Khi xưa AJ Hope-người mà doremon sẽ giới thiệu kỹ hơn ở phần sau, đã từng phải nếm trải những cảm giác rất khó chịu khi ông chứng kiến những học trò mà ông đào tạo không thu được hiệu quả như mong muốn. AJ Hope, giáo viên dạy tiếng anh được cử qua Nhật để làm phụ tá cho một giáo viên Nhật, trong 2 năm liền ông phải chứng kiến những gương mặt đượm buồn của những học trò nơi ông làm phụ tá. Học trò ở đây là những thợ thủ công, công nhân, đủ mọi tầng lớp trong ngôi làng nghèo nàn ở Nhật. Hàng ngày họ phải thức dậy sớm để lao động, tối lại phải học thêm tiếng anh để cải thiện cuộc sống, họ luôn hăng hái trong việc học tập, bất chấp cái mệt mỏi sau 1 ngày dài lao động, nhưng không một ai trong họ có thể chinh phục được tiếng anh. AJ Hope buồn phiền vì điều này rất nhiều, và nó làm ông cảm thấy xấu hổ pha lẫn chút xót xa

Doremon cũng đã gặp không biết bao topic dạng này ở các forum, biết bao thanh niên, phụ nữ tâm sự: "Mấy anh (chị), có thể giúp em tìm chỗ học tiếng anh nào đó mà giá rẻ, giáo viên dạy tốt, vì lương tháng em có 5 triệu mà phải thuê nhà...". Đến nỗi nhiều người than rằng "Bây giờ đi đâu cũng đòi bằng tiếng anh, mà lương của em thì lại không đủ đóng tiền học, có anh (chị) nào đó giúp được em không?". Đương nhiên họ cũng nhận được các câu trả lời rất nhiệt tình, nhưng đa phần là "chém gió", cuối cùng rồi cũng chẳng đâu vào đâu. Doremon nhiều khi muốn làm ngơ, nhưng nếu hình dung ra những gương mặt nghèo khổ, muốn học hành cái gì đó để thoát khỏi cái nghèo, để cải thiện cuộc sống, thì thật sự lại cảm thấy đồng cảm với họ. Rất có thể các bạn chưa gặp được những con người này, nhưng doremon đã gặp, cho nên không đành làm ngơ, nhưng nếu muốn giúp đỡ thì thời gian lại không cho phép. Hôm nay sẵn tiện viết luôn 1 bài về vấn đề này, đương nhiên bài này sẽ không rõ ràng, cụ thể, nhưng nó sẽ cung cấp cho các bạn cái nhìn chính xác nhất, cách học đúng đắn nhất, để rồi các bạn sẽ tự mình thực hiện ước mơ của riêng mình

Có bao người tự hỏi: cách giáo dục tiếng anh truyền thống có thực sự hiệu quả? có dựa trên các công trình khoa học đã được chứng minh?. Đương nhiên là không, cho nên đó là lí do tại sao, hàng nghìn, hàng triệu và hàng tỉ học sinh, sinh viên trên toàn thế giới đều thất bại với môn học này. Không riêng gì ở Việt Nam, mà ở bất kì đâu trên trái đất, nơi tồn tại lớp học có tên gọi "anh văn" thì 95% trong số học bị thất bại. Số liệu này có thể bị chênh lệch, vì doremon lấy nó từ năm 2006 của các nhà Ngôn Ngữ học. Và các bạn hãy nhớ thành công ở đây, không có nghĩa là chúng ta đọc được vài ba câu căn bản, nghe vài ba từ vu vơ... mà là chúng ta dùng được nó như ngôn ngữ mẹ đẻ. Và trái ngược với những điều này thì được gọi là thất bại-đây là tiêu chuẩn được đặt ra để khảo sát. Vì chúng ta học tiếng anh để làm gì? Để cải thiện cuộc sống, để học các tri thức được viết bằng tiếng anh, để giao tiếp với người nước ngoài, để nghe họ nói và nói cho họ nghe, chứ không phải học tiếng anh để "nổ"

Đương nhiên để thành công như tiêu chí trên là không đơn giản, nhưng chỉ có làm được như vậy thì lúc này tiếng anh mới trở nên hữu dụng, mới đi vào cuộc sống của chúng ta. Và có 1 số qui tắc sau đây cho những ai muốn thành công

1. Phải học tiếng anh bằng chính tiếng anh, có nghĩa là không được dịch. Thế tại vì sao? Khi bạn dịch đồng nghĩa với việc bạn phản xạ rất chậm, điều này không là vấn đề gì đối với việc đọc và viết, không viết khi này thì viết khi khác, không đọc quyển sách hôm nay thì ngày mai. Nhưng nó lại có vấn đề với việc nói và nghe, có ai đủ kiên nhẫn để chờ bạn dịch sau đó bạn hiểu, sau đó bạn lại tìm từ-dịch sang tiếng anh-rồi nói, bạn cũng sẽ không có đủ thời gian để nghe... Và một vấn đề rắc rối khác: bạn sẽ không thể hiểu hết ý nghĩa của 1 câu nào đó nếu bạn dịch nó sang tiếng việt, vì tiếng anh và tiếng việt là 2 thứ ngôn ngữ hoàn toàn khác nhau. Thế có cách nào không dịch mà vẫn hiểu? Có cách

2. Tuyệt đối không nên học ngữ pháp-nhận xét này đến từ các công trình của các nhà Ngôn Ngữ học, chứ không đơn thuần chỉ là nhận định cá nhân. Vì thời gian và độ dài của topic không cho phép nên doremon sẽ không kể về các công trình làm gì, ai muốn tò mò thì lên google gõ từ khoá Stephen D Krashen, sau đó sẽ tìm được thứ mình muốn. AJ Hope ví ngữ pháp như "shit", ai đó có sách ngữ pháp bằng giấy thì nên bán giấy vụn hay đốt đi là vừa, còn có ebooks thì nên delete đi. Khi chúng ta học ngữ pháp thì chúng ta sẽ làm cho bộ não có sự "trễ pha" trong việc sử lí thông tin và làm cùn mòn phản xạ tự nhiên. Chúng ta là người Việt, có ai đó nói hay viết mà phải suy nghĩ để lựa đâu là chủ ngữ, vị ngữ... hay không? Thế nhưng không ai có thể phủ nhận được, để nói giỏi và viết hay thì phải cần tới ngữ pháp, không thì người ta bảo mình ít học hay dốt smilie . Vậy ở đây có 1 sự mâu thuẫn, "không được học ngữ pháp" smilie"phải biết ngữ pháp"-có cách giải quyết, anh em yên tâm

3. Trong tất cả các phương pháp học mang lại hiệu quả nhất thì chúng có chung 1 điểm: nghe, nghe và nghe. Bọn nó được gọi chung bằng 1 cụm từ "listen first approach".Khi bạn mới chào đời thì kỹ năng đầu tiên mà bạn được học là nghe nghe và nghe, cho đến khi bạn tập nói và sau đó là lên trường để học viết. Thế nhưng phương pháp truyền thống lại đi ngược lại-đây thật sự là 1 vấn đề đối với cách giáo dục như hiện nay

4. Để nhớ 1 từ vựng thì cách tốt nhất và hiệu quả nhất là: nhớ 1 câu có chứa từ đó-đây cũng là kết luận đến từ công trình khoa học. Thế nhưng chúng ta lại học theo kiểu, viết 1 cái list từ vựng và tụng, tụng cho đến răng rụng, chân run, tay mỏi thì cũng chẳng mang lại bao nhiêu lợi ích. Cho nên việc học từ vựng hiệu quả nhất đến từ việc học cả 1 câu và đọc các câu chuyện-tức là 1 đoạn văn, hãy chọn những đoạn văn có các trạng thái cảm xúc sau: yêu thương, ghê sợ, tởm lợm, bệnh hoạn... Vì các cảm xúc này khó mà ta quên được. Vậy giờ nên đọc các cuốn truyện nào? có cách smilie

5. Để nhớ 1 từ vựng tốt hơn thì các bạn nhớ kết luận này (đương nhiên cũng là nghiên cứu khoa học): "Bạn chỉ có thể nhớ được 1 từ khi bạn nghe và nhìn thấy (hay viết) nó 30 lần trở lên trong 1 hoàn cảnh hoàn toàn hiểu được". Điều này nói lên cái gì? cách học truyền thống nên vứt thùng rác, vì nó chỉ phí thời gian, trước hết chúng ta học từ bằng cách viết từng từ đơn, thiếu phần nghe, thiếu trong 1 hoàn cảnh hiểu được (tức là phải viết thành đoạn như ý 4), và chúng ta nhìn (viết) nó không đủ 30 lần hoặc hơn, cho nên chúng ta có học cho mấy rồi cũng quên. AJ Hope đã tâm sự, ông muốn học tiếng Tây Ban Nha, và các bạn có thể đoán thử, vâng họ nhồi nhét AJ Hope học càng nhiều từ mới càng tốt, mỗi tuần mỗi bài như chúng ta, chương 1, chương 2... và sau 1 năm AJ Hope nói "Tôi quên tất cả những gì mà tôi đã học"

6. Phát triển ý 5. Đây có thể là tin buồn cho các bạn, nhưng nó là sự thật. Dù các bạn có học kỹ xảo nào đi nữa, môn học nào đi nữa thì chìa khoá để mở ra cách cửa thành công đó là: repetition-sự lặp lại và distinction-sự phân biệt. Distinction chỉ đến khi repetition đủ nhiều. Chúng ta ai cũng hiểu được những chân lí cơ bản, để giỏi trong 1 môn thể thao nào đó thì chúng ta phải tập các động tác cơ bản nhiều lần, nhiều năm. Các vận động viên quyền anh học được bao nhiêu cú đấm: khoảng 2 hay 3 cú cơ bản như đấm móc, đấm thẳng và họ thực hiện nó ngày này qua ngày nọ, năm này qua năm nọ. Đó là lí do tại sao khi chúng ta-con người bình thường đấm người khác 1 cái, có thể họ bị đau hay bất tỉnh... nhưng các vận động viên quyền anh mà đấm ta 1 cái thì nơi ta nằm không phải là trên đường, cũng không phải là trong bệnh viện mà có thể là trong quan tài. Đây chỉ là 1 ví dụ nho nhỏ để các bạn thấy được repetition có tác dụng ghê gớm đến cỡ nào, cũng cùng 1 động tác nhưng ta thực hiện nó nhiều năm thì "chất" đã khác. Đó là lí do tại sao AJ Hope là giáo viên dạy tiếng anh chứ chẳng phải là tiếng khác vì ông ta đã repetition đến hơn 40 năm, chúng ta dùng tiếng việt thành thạo bởi vì chúng ta đã repetition đến cũng gần 10-20 năm. Doremon sẽ nói rõ vấn đề này hơn ở phần sau, nhưng tin buồn đó các bạn à: repetition-một kỹ năng mà không 1 ai muốn, vì con người luôn có xu hướng mới hơn, nhiều hơn, nhanh hơn-cho nên các bạn có thể bỏ cuộc ngay tại nơi này

Vì thời gian có hạn, nên doremon sẽ chuyển qua phần chính

Các phương pháp học tiếng anh phổ biến

1. 5 bước để nói được Tiếng Anh
http://www.youtube.com/playlist?list=PL7A78B0A7E7A20419

Nhân vật này cũng được nói nhiều ở các forum với các phương pháp gì đó, mà sau khi đọc xong người ta rất hồ hởi rằng: ồ hay quá, tốt quá... Nhưng nhận định riêng của doremon thì cái này chỉ để "lừa" những ai không biết gì, qua ngôn từ thì các bạn phần nào cũng thấy được doremon không ưa nhân vật này, vì cậu ta-đang công tác ở nước nào đó, cũng chỉ dừng lại ở mức độ "nói", điều này càng tạo nên sự hỗn loạn và mơ hồ cho người học. Như về Nguyên lý 20/80
đây là hình bìa


Đây là cuốn sách rất hay có tác dụng lên nhiều lĩnh vực, anh em rãnh thì lên mạng "lượm" về đọc chơi. Nội dung của nó đại khái như sau: tính tổng thể trên toàn thế giới thì 20% lượng người lại chiếm tới 80% đất đai+tài sản (mấy ông tỷ phú đây), 80% lượng người còn lại thì eo hẹp với 20% còn thừa. Trong 1 công ty thì có 20% công nhân lại làm ra tới 80% sản phẩm cho công ty... Tương tự cho tiếng anh: trong tổng thể toàn bộ từ vựng tiếng anh thì chỉ có 20% vốn từ là được dùng nhiều và phổ biến. Nhưng rất tiếc cậu gì đó lại không chỉ rõ thế từ nào là thuộc nhóm 20% để tôi còn biết đường tôi học... Vâng tất cả chỉ là để nói, vì thời đại bây giờ mấy "ông to bà bự" nói nhiều quá mà không làm nên doremon luôn có ác cảm với những người này

2. Crazy english của Lí Dương-Trung Quốc
Nội dung của nó là học thuộc từng câu đơn sau đó học tiếp, học đến khi nào đủ nhiều thì dùng. Các bạn có thể lên google tìm cuốn 365_cau_crazy_english về xem thử cho biết, và bản mới nhất là của 1 người Việt Nam với 400 Crazy English-vào vn-zoom.com tìm. Tập hợp nhiều câu cơ bản về tiếng anh
Vì thời gian có hạn, nên anh em muốn xem thì xem, còn doremon thì nó cũng chỉ là để học cho biết, điều này hoàn toàn khác với học để thành Master, vì
1. Phương pháp hay, nhưng nó chỉ là 1 bộ phận của phương pháp mà doremon sẽ giới thiệu kỹ càng-effortless english của AJ Hope
2. Không có các công trình khoa học làm nền tảng

3. Effortless english
Đây là phương pháp nổi tiếng nhất hiện nay, với phương châm "thuận theo tự nhiên" được phát triển bởi AJ Hope-hiện đang sống tại Mỹ. Đoremon giới thiệu cho anh em bởi vì
1. Phương pháp này được xây dựng dựa trên rất nhiều công trình khoa học về Ngôn Ngữ học và các mảng kiến thức khác
2. AJ Hope không chỉ nói mà ông ta còn thiết kế 1 hệ thông để các bạn học
Đây là toàn bộ giáo trình của AJ Hope hiện đang lưu hành trên mạng


Các bạn có thể tự tìm tài liệu, còn doremon chỉ có thể giới thiệu hình bìa, tên sách vì thời gian không cho phép. Trong tất cả các phần trên thì phần quan trọng nhất là: Power English Now. Trong phần này AJ Hope cung cấp cho chúng ta các bài đọc tuyệt vời về cách học tiếng anh. Các bạn hãy tự đọc sau đó hãy tự biết cách học vì doremon không đủ thời gian để miêu tả. Nếu các bạn không hiểu được nội dung của phương pháp này mà học bừa như trên mạng thì thật sự là vô cùng phí phạm, vì tất cả các bài học AJ Hope đã thiết kế, đều ẩn chứa hàm ý trong đó, và các bạn chỉ có thể hiểu nếu các bạn đọc toàn bộ 30 bài Main Text. Nhiều bạn không đọc kỹ mà lụi vào học bừa, lúc này Effortless english cũng chỉ như bao phương pháp khác, cũng nghe, cũng nói... Nhưng điều này rất nguy hiểm, bạn vào HVA có thể không thèm đọc nội qui, vẫn sinh hoạt như thường, nhưng nếu bạn dùng thuốc mà không đọc hướng dẫn thì có thể chết như chơi, học mà không hiểu nội dung của phương pháp thì cũng như "sấm bên tai", nghe xong rồi vứt

Một số kỹ xảo bắt buộc phải học
Đoremon sẽ cung cấp cho các bạn 1 số công cụ để học kèm với Effortless english. Đương nhiên AJ Hope không thể cung cấp toàn bộ giáo trình cho chúng ta, mà ông ta chỉ xây dựng hệ thống, và chúng ta phải tự biết cách tìm kiếm các phần còn lại. Quên, giờ mới nhớ, mỗi bài học của AJ Hope phải mua đó nhé, đây là đang học chùa smilie

1. Luyện nói
Hãy quên đi việc học tiếng anh chỉ để dịch tài liệu, mà không cần nói với nghe. Bốn kỹ năng: nghe, đọc (đọc sách bằng mắt), nói, viết có mối quan hệ tương hỗ với nhau. Theo Effortless english, việc viết hay-đồng nghĩa với việc giỏi ngữ pháp bắt nguồn từ việc đọc nhiều. Đây chính là câu trả lời cho các bạn về vấn đề: không cần học ngữ pháp nhưng vẫn giỏi ngữ pháp. Việc giỏi ngữ pháp không phải là kết quả của việc mổ xẻ 1 câu nào đó để phân tích và học cấu trúc câu, mà nó là kết quả của việc đọc nhiều-đây là kết luận của nhà Ngôn Ngữ học hàng đầu thế giới Stephen D Krashen. Ông ta viết (tạm dịch qua tiếng việt) "khi bạn đọc một ngôn ngữ nào đó thì bạn không còn cách nào khác ngoài việc phải phát triển khả năng đọc-có nghĩa là bạn phải làm quen với các dạng câu, các dấu chấm phảy..." đương nhiên khi bạn đã quen rồi thì bạn sẽ lấy câu đó để dùng lại cho việc viết của mình, cho nên tiếp tục "chúng ta ít khi nào phát hiện được lỗi ngữ pháp từ những người đọc nhiều". Vấn đề này sẽ được nói rõ hơn ở phần luyện đọc, khi việc đọc phát triển-dẫn tới việc viết phát triển-dẫn tới việc nghe phát triển-dẫn tới việc nói phát triển-và cắn đuôi lại là dẫn tới việc đọc phát triển. Trong 4 mắt xích này chỉ cần 1 mắt xích bị phá vỡ thì bạn không thể nào trở thành 1 Master of English
Chú ý: Tuyệt đối nghiêm cấm luyện nói bằng phần mềm-vì âm bị méo-không chính xác

Các giáo trình sau:
1 American spoken english (video)
Đây là hình ảnh



Miêu tả: chương trình này cực kì hay, nó có hình ảnh minh hoạ (phim), và cực kì căn bản. Cái cần học trong chương trình này: đọc các từ căn bản và đọc các từ nối-quan trọng, vì người Mỹ-Anh ít khi đọc từng từ riêng lẻ mà họ đọc nó dính lại
VD: Why is he.... (đọc dính is và he thành quai í she)

Hạn chế: chỉ phát âm 1 vài âm cơ bản

2. Pronunciation workshop
Đây là hình ảnh



Miêu tả: dùng để khắc phục các âm còn thiếu trong chương trình 1, nên không cần học hết, chú ý các âm khó là : th, vd: math, teeth. Hãy cố gắng uốn lưỡi giống như hình ảnh trong clip để phát âm đúng âm th-rất khó đấy nhé

3. Mastering the American Accent
Đây là hình ảnh



Miêu tả: không có clip, nhưng bù lại lượng từ rất là nhiều, và các bạn chỉ được học cái này khi đã xong cái 1 và 2, vì 1 và 2 sẽ cung cấp cho bạn hình ảnh về cách uốn lưỡi, cách đọc âm gió... Cái số 3 là cái kết thúc trong phần luyện nói, sau khi học xong cái số 3 bạn sẽ biết được các qui tắc phát âm cơ bản, đọc nối từ, 1 từ có nhiều cách đọc
vd: I'll: đọc ai qiêu hay ai o hay o

Doremon có khoảng 8 chương trình phát âm, nhưng post lên nữa là thừa, chỉ cần 3 cái trên là đủ

2. Luyện nghe
Các bạn đặc biệt chú ý, nếu các bạn muốn theo lời khuyên của doremon thì chỉ nên học Effectless English sau 6 tháng khổ luyện, lí do sẽ trình bày sau
Việc luyện nghe như đã nói ở phần đầu, nếu các bạn chịu đọc kỹ. Nghe-nghe-và nghe- đây là kỹ năng đầu tiên cần được phát triển, thiếu nó-mọi thứ đều vứt. Thế tôi nên nghe cái gì? vì không phải cái nào cũng nên nghe. Hiện doremon có khoảng 20GB tài liệu luyện nghe, nhưng sẽ không post lên đây. Dù các bạn có luyện nghe như thế nào, thì hãy tuân thủ kết quả đã được kiểm nghiệm như đã nói: "Bạn chỉ có thể nhớ được 1 từ khi bạn nghe và nhìn thấy (hay viết) nó 30 lần trở lên trong 1 hoàn cảnh hoàn toàn hiểu được". Do vậy các bạn có thể lựa chọn bất cứ giáo trình nào miễn: có file pdf + audio+đoạn văn. Có nghĩa là luyện nghe bằng cách nghe người ta đọc các đoạn văn và vừa nghe vừa nhìn vào file pdf (đồng thời các bạn cũng đang phát triển khả năng đọc như đã nói ở trên). Các giáo trình như trên rất hiếm, vì doremon đã rất khó khăn để tìm ra nó, đa phần là đọc bài text hay các bài văn quá dài-không phù hợp với người nhập môn. Đoremon giới thiệu giáo trình sau

1. Listening_Practice_Through_Dictation
Đây là hình ảnh



Gồm 4 cấp độ, mỗi cấp độ gồm 30 bài, mỗi bài có độ dài như ảnh



Như vậy nó thoả mãn: vừa đọc pdf+ vừa nghe audio+đoạn văn ngắn+bài văn dễ hiểu không dùng slang hay idiom

Giáo trình này nên học như sau: nên nghe 1 mỗi bài vài lần và sau đó chuyển qua bài khác. Và mục tiêu cuối cùng là học thuộc (cái này liên quan đến phương pháp của Lí Dương). Và doremon sẽ nhắc lại chìa khoá để thành công: repetition and distinction. Đây là điều mà bất cứ một chuyên gia nào cũng phải thừa nhận, và bất cứ 1 người nào cũng phải ngán ngẫm. Bạn không đủ khả năng kiên trì để repetition and distinction thì nên bỏ cuộc để khỏi thất vọng. Distinction như đã nói chỉ đến khi repetition đủ nhiều, do vậy nó là trạng thái cao hơn của repetition
VD: Hãy xem 2 câu sau I can not wait và I can wait. Nếu là người Anh thì can: đọc là cen, còn cannot: đọc là can. Còn người Mỹ thì can và cannot đọc như nhau, vì người Mỹ thì âm a đọc giống âm e. Vậy làm sao để ta phân biệt? câu trả lời distinction-sự khác biệt. Còn rất nhiều từ mà hầu như chúng đọc hoàn toàn như nhau, cho nên ta không thể nào phân biệt chúng bằng âm mà phải phân biệt chúng bằng nghĩa. Để làm được điều này thì các bạn phải đạt đến trình độ nào đó bằng cách repetition thật nhiều. Một vị khách lạ đến thăm thành phố chúng ta, ngày đầu tiên ông ta sẽ thấy mọi thứ đều như nhau: con đường, nhà cửa.... nhưng nếu ông ta sống lâu thì ông ta sẽ dần phân biệt được đâu là nhà ông A, nhà bà B, nhà con C và nhà thằng D...

AJ Hope có hỏi bí quyết của 1 học trò-người tiến bộ nhanh nhất trong lớp, và người này trả lời như sau: vì muốn để đạt đến trình độ Master mà người này đã nghe cùng 1 bài nhưng lặp lại tới 500 lần. Có thể các bạn sẽ không tin-như doremon khi ngày nào còn tập tò. Nhưng sau khi đã hiểu về chìa khoá của repetition thì: có những bài trong giáo trình trên doremon nghe hơn 1000 lần-vâng có thể các bạn không tin. Nhưng doremon cũng như người bình thường, mức nhẫn nại cũng có giới hạn, cho nên cứ ngồi đó mà đếm 1 , 2... 1000 chắc điên. Vậy bí quyết là ở chỗ nào? Mỗi 1 ngày doremon đặt mục tiêu nghe 1 bài trong giáo trình đó 5 lần, 1 bài đó ngắn khoảng 1 phút 30'. Sau đó chuyển qua nghe bài khác và cứ thế theo năm theo tháng cho đến khi nhớ toàn bộ từ vựng cũng như ý nghĩa của bài thì ngừng

Cho nên: hãy nghe cho tới khi phân biệt được từng từ trong đoạn văn, ban đầu không cần quan tâm đến cái nghĩa, chỉ đặt mục tiêu là nghe và phân biệt các từ, kết hợp với việc luyện nói như đã trình bày, sau khi nghe đủ nhiều và luyện nói hết 3 giáo trình ở trên, thì vứt chúng đi để tiến lên trình độ cao. Đọc lại toàn bộ bài văn mà các bạn đã luyện nghe nhiều lần. Vừa đọc + kết hợp nút pause để đọc làm sao cho giống như người ta đã đọc cho mình nghe suốt thời gian qua. Hãy nhớ, đọc to thành tiếng (không phải đọc thầm nhé), thậm chí là gào lên cũng được. Các bạn đọc càng to thì tiếng anh sẽ ngấm vào cơ thể bạn càng nhiều. Cứ như thế khi đọc được khoảng 15 bài, thì chuyển lên nghe các bài chưa nghe, các bài đã nghe nhiều lần thì chuyển qua đọc to không nghe nữa, sau khi đọc đủ nhiều, thì lúc này bài văn đó gần như đã "ngấm" vào trong thân thể các bạn. Và tới giai đoạn repetition quan trọng nhất: học thuộc và hiểu nghĩa. Đây là công việc đơn giản vì các bạn đã nghe và đọc nó nhiều lần thì việc học thuộc rất dễ, còn về nghĩa từ nào không biết thì cứ tra từ điển để hiểu. Sau đó đọc to lại lần nữa nhưng ở mức cao hơn, đó là các bạn biết ý nghĩa của cái câu, đoạn văn mà mình đọc. Cứ như thế cho đến hết 120 bài của 4 cấp độ thì: vốn từ vựng đã nhiều và hầu như khó có thể quên được+có thể hiểu được những câu mà mình đã gặp trong 120 bài mà không cần phải dịch: vì các bạn đã nghe và đọc và viết câu đó quá nhiều lần
VD: câu I love you-Một câu không cần dịch cũng hiểu vì các bạn đã repetition quá nhiều

Đặt mục tiêu 6 tháng hết cái này sau đó các bạn mới đủ lượng từ vựng để hiểu phần nào nội dung của Effectless English-sau hi hiểu được nó thì lúc này các bạn dùng sao để đi đến đích là việc còn lại của các bạn

2. Các giáo trình luyện nghe tiếp theo

Xem phim-thật sự là 1 điều phí phạm nếu bạn không luyện tiếng anh bằng cách xem phim, vì:
1. Khi xem phim bạn sẽ có đủ các yếu tố: người nói+ cử chỉ+ cảm xúc... cho nên bạn sẽ phần nào nhạy bén hơn trong việc hiểu câu tiếng anh, ví dụ nhân vật nói: this is my book và ông ta chỉ vào quyển sách trên tay thì ta cũng đoán được nghĩ của cái câu
2. Khi xem phim các bạn không có đủ thời gian để dịch, để phân tích ngữ pháp... vì khi làm điều này các bạn sẽ không bắt kịp nhịp phim, cho nên nó làm cho bộ óc tăng khả năng phản xạ, có nghĩa là tăng khả năng: hiểu mà không cần dịch

Không nên xem các bộ phim vốn chỉ dành cho dân "truyền thống" như extr@, vì các bộ phim này mục đích là nói cho chúng ta nghe, nên họ sẽ nói thật chậm và ít dùng slang hay idiom, nói tóm lại đó là "ngôn ngữ chết". Hãy coi các bộ phim mà họ nói cho người của họ nghe-Anh-Mỹ... nói tóm lại đây là "ngôn ngữ sống". Nên xem các thể loại: kinh dị, máu me, ám ảnh, hài, tình yêu.... vì như đã nói ở phần đầu, cũng từ các công trình khoa học mà ra: các cảm giác rùng rợn, ghê tởm, hài hước, cảm động sẽ in sâu vào trong bộ não chúng ta. Có những tập phim doremon coi xong mà nhớ luôn cái từ tiếng anh đó, như red mouth-vì từ này đi kèm với 1 cái miệng của 1 con quái vật đầy máu

Chú ý: khi xem phim không bao giờ được dịch và phải coi kèm với sub, không hiểu thì kệ nó đừng có pause để dịch, cứ để tiếng anh vào tai 1 cách tự nhiên, và theo dõi sub trên màn hình. Tự động bộ não của chúng ta sẽ thích nghi và sau thời gian dài nó sẽ hiểu-cái này AJ Hope có nói-đọc Effectless English sẽ thấy

Các bộ phim nên xem
1. Friends
Không có ngôn từ nào để diễn tả sự tuyệt vời của 10 season hài Friends-đây là một bộ phim để chúng ta học tiếng anh thực sự vì: nói rất nhiều, hài tuyệt vời, diễn xuất cực hay, xem hoài không chán
Đánh giá: 10
Bộ phim này cần xem đi xem lại nhiều lần, và doremon xem mỗi tập ít nhất 6 lần. Lưu ý: gồm 10 season, mỗi season gồm khoảng 24 tập, mỗi tập khoảng 25 phút smilie

Khi nào đạt đến trình độ coi không cần sub và hiểu được lí do tại sao họ cười thì xem như bạn đã đạt đến 1 trình độ khá cao. Muốn làm điều này thì: phải tranh thủ luyện đọc, luyện nói, luyện viết để vốn từ vựng tăng dần. Phim chỉ có nhiệm vụ như sau: cung cấp hình ảnh để diễn tả cái từ, cái câu và bắt bộ não phải phản xạ thật nhanh. Cho nên đừng tưởng coi phim là học từ vựng. Học từ vựng là ở giai đoạn trước: nghe+đọc lại+ viết lại+ đọc lại tiếp. Như vậy sẽ chẳng ích gì nếu bạn chỉ coi phim, trái lại nếu bạn học đi kèm với các kỹ năng kia thì có thể trong bài văn nào đó bạn không thể hiểu được vài câu, thì khi coi phim bạn gặp lại câu đó và thấy họ hành động, do vậy bạn sẽ hiểu

2. Hannah Montana

Đánh giá: 8
Gồm 4 season-coi hài và có mấy bé xinh lắm

3. How I met your mother
Đánh giá: 5
Gồm 6 season, mức độ hài dở, hơi nghiêng về tình cảm nhưng tuyệt vời là sub trùng hoàn toàn-mấy season trên có cái sub không trùng

4. The Suite Life of Zack and Cody

Đánh giá: 7
Gồm 3 season, chỉ có sub vài tập, nhưng được cái có cô bé đáng iu lắm smilie -

5. Thời sự Nhà Trắng-Whitehouse

http://www.youtube.com/user/whitehouse

Dành cho trình độ cấp cao

Còn nhiều nữa nhưng thôi-tốn thời gian quá
Ráng viết cho hết chứ tốn 5h của doremon rùi



3. Luyện đọc

Đây là giai đoạn sau cùng, nhưng lại quan trọng nhất vì:
1. Nó có tác dụng cung cấp từ vựng
2. Có tác dụng cung cấp ngữ pháp
3. Đọc để tiếp thu tri thức của nhân loại bằng tiếng anh

Hãy đảm bảo rằng bạn đã học hết hoàn toàn lượng từ vựng của Power English Now-Effectless English, và 120 bài nói ở phần luyện nghe. Vì khi tới giai đoạn luyện đọc thì lúc này các bạn đã gần như tới đích: các bạn đã nghe nhiều (xem phim+nghe 120 bài+ nghe AJHope...), đọc to rõ ràng không biết bao nhiêu bài và viết cũng không ít. Chỉ khi nào làm được điều này thì các bạn mới đủ khả năng để đọc 1 cuốn sách bằng tiếng anh mà không cần dịch, có thể đoán được nghĩa của từ mà không cần tra từ điển. Vì đọc ở đây, mục tiêu là để "thấm" tiếng anh, có nghĩa là thích thú về câu chuyện hài, ghê sợ không ngủ được vì đọc Edgar Allan Poe-tác giả truyện kinh dị rất nổi tiếng, hay khóc sướt mướt về 1 tình yêu ngang trái nào đó... chứ không phải đọc để rồi các bạn còn phải tra từng từ-đọc như vầy thì rất nản và không thu được gì. Đương nhiên giai đoạn đầu thì các bạn chưa thể đọc mấy ông "khủng" như Stephen King, Alan Watts, mà các bạn phải đọc câu chuyện thiếu nhi, sách dành cho các bé mẫu giáo hay lớp 1-5. Các truyện này có hình ảnh, ít trang, ít từ vựng, và giàu tính nhân văn, cho nên khi đọc sách này với lượng từ vựng hiện có thì các bạn sẽ không lo gì việc tra từ vựng mà chỉ có việc đọc để thích. Và cứ thế ta tăng dần cấp độ, nên qua mỗi cuốn sách các bạn sẽ học được vài ba từ vựng-lúc này các bạn sẽ học từ vựng rất nhanh vì các bạn đã có vốn sẵn, hơn nữa trong câu chuyện thì nhiều từ lặp đi lặp lặp lại rất rất nhiều lần
VD: đọc mấy cuốn liên quan đến biển thì mấy từ như sea ,wave, water.... lại lại nhiều lắm

EJ Hope nói "chỉ cần bạn đọc 1 ngày 1 cuốn, 1 cuốn khoảng gần 100 trang thì sau 1 năm, bạn sẽ đọc được những cuốn sách mà tôi đang đọc"

Vài cuốn:






Đọc bằng cách xem truyện tranh: đây là 1 cách đọc tuyệt vời
vd: bộ doremon-nhân vật iu thích của tui



Đây là trang web cung cấp nguồn truyện tranh bằng tiếng anh khổng lồ
http://vnsharing.net/forum/showthread.php?t=1829

Định viết dài hơn, kỹ hơn, cũng cấp tài liệu nhiều hơn, nhưng thời gian có hạn, anh em thông cảm. Ngồi viết gần 6h đau lưng, mỏi cổ quá

Trước khi kết thúc, có vài lời nhắn nhủ

1. Theo các kết quả khoa học trên mặt bằng chung: Trong 2 năm đầu tiên sinh viên-học sinh sẽ không có đủ khả năng để dùng tiếng anh như tiếng mẹ đẻ. Có nghĩa là bạn nên đặt ra mục tiêu rõ ràng và đừng nản lòng vì tại sao tôi học hoài vẫn không tiến bộ, đừng tin vào mấy cái "miệng bô bô" của những trung tâm, hay gì đó, sau 6 tháng hay 9 tháng bạn sẽ nói tiếng anh như "gió". Ngay cả AJ Hope-các bạn đừng hiểu lầm, ông ta có quảng cáo là chỉ cần học theo phương pháp của ông ta thì sau 6 tháng bạn sẽ nói được tiếng anh 1 cách tự nhiên. Đương nhiên đây là 1 hình thức quảng cáo để cạnh tranh, nhưng AJ Hope cũng có nói trong 1 clip rằng: 6 tháng là không thể nào biến bạn thành 1 chuyên gia anh văn, nhưng 6 tháng sẽ biến bạn thành 1 người biết cách học để trở thành chuyên gia anh văn

2. Đừng tin vào những kẻ "bô bô", vì trình độ của họ tới đâu thì khi bạn chinh phục được tiếng anh bạn sẽ hiểu, bản thân của doremon cũng từng đi xem thử các thông dịch viên làm ăn thế nào. Thật đang thất vọng, họ hầu như diễn đạt 1 cách quá "nông" ý mà người Anh muốn nói, đâm ra phiên dịch sai nhiều chỗ, chỗ nào bí thì nói đại vài câu í ớ gì đó. Còn bản thân ông nước ngoài có biết tiếng việt đâu mà biết dịch đúng hay sai. Cho nên đừng tự tin rằng mình yếu anh văn, còn người ta giỏi, nhiều người cũng dốt như ta nhưng họ lại "khéo" che đậy

3. Chúng ta học là để thành Master cho nên đừng nôn nóng, vì chỉ khi đạt đến trình độ Master bạn mới dùng nó để học các tri thức khác, mới vươn ra thế giới được-lúc này tiếng anh mới thật sự hữu ích. Hãy ráng phấn đấu và ráng nghiên cứu kỹ phương pháp Effectless English và chú ý bài 9 Kaizen way

Bản thân doremon khổ luyện 1 ngày học tiếng anh không dưới 10 tiếng và sau 7 tháng thì có thể đọc sách và truyện thiếu nhi bằng tiếng anh vô tư. Nếu các bạn không có đủ thời gian như doremon thì cũng ráng 1 ngày dành ra 6 tiếng để: tập nói, tập nghe (giai đoạn 3 tháng đầu), sau đó tập viết và cuối cùng là đọc. Và hãy nhớ là không bỏ ngày nào, lí do vì sao? Câu trả lời nằm trong bài 9 Kaize Text của Effectless English phần Power English Now. Nếu mệt hay nản thì xem phim bằng tiếng anh, vừa giải trí vừa học

Tuesday, March 27, 2012

Signal handling in Linux

Source: http://www.alexonlinux.com/signal-handling-in-linux

Table of contents

Introduction
What are signals?
Signal as interrupt
Signal masks
What signals are good for
Signals that report exceptions
Other uses of signals
Types of signals
Handling exception signals
SIGKILL and SIGSTOP
SIGKILL
SIGSTOP
Registering signal handler
signal()
Ignoring signals and restoring original signal handler function
sigaction()
sigaction() in action
Conclusion

Introduction
Perhaps any engineer developing for Linux encounters this problem. What’s is the right way to terminate the program? What are the ways to receive notifications from operating system about events that occur.
Traditional Unix systems have the answers ready. The answer to these questions is signals.
This article addresses these questions. Here, I’ll try to explain what signals are, their nature. We’ll talk about what are the right ways to handle signals, what signals to handle and what are the pitfalls of signal handling in Linux in particular.

What are signals?
Signal is a notification, a message sent by either operating system or some application to your program (or one of its threads).
Each signal identified by a number, from 1 to 31. Signals don’t carry any argument and their names are mostly self explanatory. For instance SIGKILL or signal number 9 tells the program that someone tries to kill it.

Signal as interrupt
In addition to informative nature of signals, they also interrupt your program. I.e to handle a signal, one of the threads in your program, stops its execution and temporarily switches to signal handler. Note that as in version 2.6 of Linux kernel, most of the signals interrupt only one thread and not the entire application as it used to be once. Moreover, signal handler itself can be interrupted by some other signal.

Signal masks
Each one of signals can be in one of three states:
  • We may have our own signal handler for the signal.
  • Signal may be handled by the default handler. Every signal has its default handler function. For instance, SIGINT default handler will terminate your application.
  • Signal may be ignored. Ignoring signal sometimes referred to as blocking signal.
When manipulating signals and managing signal configuration, it is often easier to manage a so called signal mask. It is a bit-mask, where each bit has a corresponding signal. There are 32 (actually 31, 0 doesn’t count) different signals, thus we can use single 32-bit integer (unsigned int) to keep information about 32 signals. This is exactly what operating system does. Moreover, signal masks used as arguments in different system calls, thus we will have to work with signal masks.
The C library assigns default signal handlers. This means that even if you leave signals untouched, your program will process signals and will respond to them according to default behavior. I will describe default signal behavior a little later in this article.

What signals are good for
Signals, as their name implies, used to signal something. There are several types of signals, each indicating something of its own. For instance SIGINT that I already mentioned, tells your program that someone tries to interrupt it with CTRL-C.
Dedication of each signal is a matter of semantics. I.e. you may want to decide what action shall be associated with each one of the signals. You may decide that some signal will cause your program to print something or draw something on the screen. It is up to you, most of the time. However, there is a common convention of what each and every signal should do. According to this common convention SIGINT expected to cause your program to terminate itself. This is the default response for SIGINT signal and it is in your interest to keep it this way. It is a question of usability. No one wants a program that cannot be interrupted.

Signals that report exceptions
Another way of using signals is to indicate that that something bad have happened. For instance when your program causes a segmentation fault, operating system sends SIGSEGV signal to your application.

Other uses of signals
Signals have several different usages. For instance debuggers rely on signals to receive events about programs that being debugged (read more about this in my article How Debugger Works). Signals is one of so called IPC – Inter Process Communication mechanisms. IPC used to, as the abbreviation implies, to allow processes communicate with one another.
Another common use is when user wishes that our program will reinitialize itself, but not terminate. In this case, user can send our program a signal from the terminal, using a program called kill. You may be already familiar with this program. It used to kill processes. The truth is that it sends a signal. Each signal has a number that identifies it. By default it sends signal 15, SIGTERM, but it can send just any signal.
Lets see most common and their use.

Types of signals
  • SIGHUP
    This signal indicates that someone has killed the controlling terminal. For instance, lets say our program runs in xterm or in gnome-terminal. When someone kills the terminal program, without killing applications running inside of terminal window, operating system sends SIGHUP to the program. Default handler for this signal will terminate your program.
    Thanks to Mark Pettit for the tip.
  • SIGINT
    This is the signal that being sent to your application when it is running in a foreground in a terminal and someone presses CTRL-C. Default handler of this signal will quietly terminate your program.
  • SIGQUIT
    Again, according to documentation, this signal means “Quit from keyboard”. In reality I couldn’t find who sends this signal. I.e. you can only send it explicitly.
  • SIGILL
    Illegal instruction signal. This is a exception signal, sent to your application by the operating system when it encounters an illegal instruction inside of your program. Something like this may happen when executable file of your program has been corrupted. Another option is when your program loads dynamic library that has been corrupted. Consider this as an exception of a kind, but the one that is very unlikely to happen.
  • SIGABRT
    Abort signal means you used used abort() API inside of your program. It is yet another method to terminate your program. abort() issues SIGABRT signal which in its term terminates your program (unless handled by your custom handler). It is up to you to decide whether you want to use abort() or not.
  • SIGFPE
    Floating point exception. This is another exception signal, issued by operating system when your application caused an exception.
  • SIGSEGV
    This is an exception signal as well. Operating system sends a program this signal when it tries to access memory that does not belong to it.
  • SIGPIPE
    Broken pipe. As documentation states, this signal sent to your program when you try to write into pipe (another IPC) with no readers on the other side.
  • SIGALRM
    Alarm signal. Sent to your program using alarm() system call. The alarm() system call is basically a timer that allows you to receive SIGALRM in preconfigured number of seconds. This can be handy, although there are more accurate timer API out there.
  • SIGTERM
    This signal tells your program to terminate itself. Consider this as a signal to cleanly shut down while SIGKILL is an abnormal termination signal.
  • SIGCHLD
    Tells you that a child process of your program has stopped or terminated. This is handy when you wish to synchronize your process with a process with its child.
  • SIGUSR1 and SIGUSR2
    Finally, SIGUSR1 and SIGUSR2 are two signals that have no predefined meaning and are left for your consideration. You may use these signals to synchronise your program with some other program or to communicate with it.
Handling exception signals
In general I think it would be a good advice to avoid changing signal handler for these signals. Default signal handler for these signals generates core file. Later, you can use core file to analyze the problem and perhaps find a solution. Overwriting signal handler for one of the exception signals, will cause your program to ignore this signal and an exception that has caused the signal. This is something that you don’t want to do.
In case you still want to handle exception signals, read my How to handle SIGSEGV, but also generate a core dump article.

SIGKILL and SIGSTOP
These two signals are special. You cannot change how your program handles these two.

SIGKILL
SIGKILL, on the contrary to SIGTERM, indicates abnormal termination of the program. You cannot change how your program handles it. It will always terminate your program. However, you can send this signal.
SIGKILL’s value is 9. This is why kill -9 <pid> shell command is so effective – it sends SIGKILL signal to the process.

SIGSTOP
SIGSTOP used when debugging. When you debug your program, operating system sends SIGSTOP to stop your program, for instance in case it reaches a breakpoint. Operating system does not let you change its handler because you may cause your program to be undebuggable.

Registering signal handler
There are several interfaces that allow you to register your own signal handler.

signal()
This is the oldest one. It accepts two arguments, first signal number (one of those SIGsomething) and second pointer to a signal handler function. Signal handler function returns void and accepts single integer argument that represents a signal number that has been sent. This way you can use the same signal handler function for several different signals.
Here is a short code snippet demonstrating how to use it.
01
#include <stdio.h>
02
#include <stdlib.h>
03
#include <signal.h>
04

05
void sig_handler(int signum)
06
{
07
    printf("Received signal %d\n", signum);
08
}
09

10
int main()
11
{
12
    signal(SIGINT, sig_handler);
13
    sleep(10); // This is your chance to press CTRL-C
14
    return 0;
15
}
This nice and small application registers its own SIGINT signal. Try compiling this small program. See what is happening when you run it and press CTRL-C.

Ignoring signals and restoring original signal handler function
Using signal() you can set default signal handler for certain signal to be used. You can also tell the system that you would like to ignore certain signal. To ignore the signal, specify SIG_IGN as a signal handler. To restore default signal handler, specify SIG_DFL as signal handler.
Although this seems to be everything you may need, it is better to avoid using signal(). There’s a portability problem with this system call. I.e. it behaves differently on different operating systems. There’s a newer system call that does everything signal() does and also gives slightly more information about the actual signal, its origin, etc.

sigaction()
sigaction() is another system call that manipulates signal handler. It is much more advanced comparing to good old signal(). Let us take a look at its declaration
int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
Its first argument specifies a signal number. Second and third arguments are pointers to structure called sigaction. This structure specifies how process should handle given signal.
1
struct sigaction
2
{
3
    void (*sa_handler)(int signum);
4
    void (*sa_sigaction)(int signum, siginfo_t *siginfo,
5
        void *uctx);
6
    sigset_t sa_mask;
7
    int sa_flags;
8
    void (*sa_restorer)(void);
9
};
sa_handler is a pointer to the signal handler routine. The routine accepts single integer number containing signal number that it handles and returns void – same as signal handler registered by signal(). In addition, sigaction() let you have more advanced signal handler routine. If needed sa_sigaction pointer should point to the advanced signal handler routine. This one receives much more information about the origin of the signal.
To use sa_sigaction routine, make sure to set SA_SIGINFO flag in sa_flags member of struct sigaction. Similarily to sa_handler, sa_sigaction receives an integer telling it what signal has been triggered. In addition it receives a pointer to structure called siginfo_t. It describes the origin of the signal. For instance, si_pid member of siginfo_t holds the process ID of the process that has sent the signal. There are several other fields that tell you lots of useful information about the signal. You can find all the details on sigaction‘s manual page (man sigaction).
Last argument received by sa_sigaction handler is a pointer to ucontext_t. This type different from architecture to architecture. My advice to you is to ignore this pointer, unless you are writing a new debugger.
One additional advantage of sigaction() compared to signal() is that it allows you to tell operating system what signals can handle signal you are registering. I.e. it gives you full control over what signals can arrive, while your program handling another signal.
To tell this, you should manipulate sa_mask member of the struct sigaction. Note that is a sigset_t field. sigset_t type represents signal masks. To manipulate signal masks, use one of the following functions:
  • int sigemptyset(sigset_t *) – to clear the mask.
  • int sigfillset(sigset_t *) – to set all bits in the mask.
  • int sigaddset(sigset_t *, int signum) – to set bit that represents certain signal.
  • int sigdelset(sigset_t *, int signum) – to clear bit that represents certain signal.
  • int sigismember(sigset_t *, int signum) – to check status of certain signal in a mask.
sigaction() in action
To conclude, I would like to show a small program that demonstrates sigaction() in use. I would like the program to register signal handler for SIGTERM and then, when it receives the signal, print some information about the origin of the signal.
On the other hand, I will use Python interpretor to send the program a signal.
Here is a program.
01
#include <stdio.h>
02
#include <signal.h>
03
#include <string.h>
04
#include <unistd.h>
05

06
struct sigaction act;
07

08
void sighandler(int signum, siginfo_t *info, void *ptr)
09
{
10
    printf("Received signal %d\n", signum);
11
    printf("Signal originates from process %lu\n",
12
        (unsigned long)info->si_pid);
13
}
14

15
int main()
16
{
17
    printf("I am %lu\n", (unsigned long)getpid());
18

19
    memset(&act, 0, sizeof(act));
20

21
    act.sa_sigaction = sighandler;
22
    act.sa_flags = SA_SIGINFO;
23

24
    sigaction(SIGTERM, &act, NULL);
25

26
    // Waiting for CTRL+C...
27
    sleep(100);
28

29
    return 0;
30
}
And this is what happens when we try to run it. First we run the program.
~/works/sigs --> ./a.out
I am 18074
While it sleeps I ran Python shell and killed it.
~ --> python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:31:22)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import signal
>>> print os.getpid()
18075
>>> os.kill(18074, signal.SIGTERM)
>>>
Here’s the rest of the output of the program.
~/lab/sigs --> ./a.out
I am 18074
Received signal 15
Signal originates from process 18075
~/lab/sigs -->
We can see that it recognized the process that has killed it and printed its process ID.

Conclusion
I hope you found this article interesting. If you have questions, don’t hesitate to email me to alex@alexonlinux.com.