Kill all of the specific process:
killall -9 <command name>
This is different a little from UNIX, BE CAREFUL!!
Thursday, 24 February 2011
Saturday, 19 February 2011
Found a Bug in jBittorrentAPI
Actually, this is my first time to find some bugs in other's work.....
In it's TorrentProcessor class, it get the value of file length using a Long.inValue. The precision has been lost a lot, even if it assign it back to a long value. Because of this bug, I got a overflowed number with minus to be inserted into mysql's unsigned big int column!! Obviously, a error message is obtained.
Actually, the reason that I will use this package is that, it can read all of the files that C version's bencode program can not read. Whenever I process the files from Pirate Bay, there would be a segmentation fault sent back to me.
Good work for jBittorrentAPI.....
In it's TorrentProcessor class, it get the value of file length using a Long.inValue. The precision has been lost a lot, even if it assign it back to a long value. Because of this bug, I got a overflowed number with minus to be inserted into mysql's unsigned big int column!! Obviously, a error message is obtained.
Actually, the reason that I will use this package is that, it can read all of the files that C version's bencode program can not read. Whenever I process the files from Pirate Bay, there would be a segmentation fault sent back to me.
Good work for jBittorrentAPI.....
Change table properties in MySQL::
The most basic one is :
ALTER TABLE person MODIFY person_id SMALLINT UNSIGNED AUTO_INCREMENT;
More detailed can be found here:
ALTER TABLE person MODIFY person_id SMALLINT UNSIGNED AUTO_INCREMENT;
More detailed can be found here:
http://dev.mysql.com/doc/refman/5.1/en/alter-table.html
What if you encounter an error message of "out of heap" in Java?
At this time, you need to:
(1). check the program and find out any possibility to free the unnecessary resource.
(2). increase your heap size to achieve more memory allocated to java.
Here I only care about the later one:
(1). check the program and find out any possibility to free the unnecessary resource.
(2). increase your heap size to achieve more memory allocated to java.
Here I only care about the later one:
java -Xms<initial heap size> -Xmx<maximum heap size>
Defaults are:
java -Xms32m -Xmx128mUsage of u_int32_t and size_t
Actually, the usage of these kinds of types confused me for a quite long time, because I really don't know what's the differences between these types and the C's primitive types such as 'int'?
The C's primitive types such as 'long', 'int' are machine dependent, which means different types system probably has different definition of long and int. For example, in old x86 (486), 'int' may be defined by 2 bytes. However, it is 4 bytes in most machines nowadays. In this case, 'u_int32_t' or 'int32_t' is invented to be a system independent type. In fedora, they are defined in file '/usr/include/sys/types.h', 'u_int32_t' is only possible to be a 'int' type with 32bit (4 bytes). This will provide the program with being portable.
The C's primitive types such as 'long', 'int' are machine dependent, which means different types system probably has different definition of long and int. For example, in old x86 (486), 'int' may be defined by 2 bytes. However, it is 4 bytes in most machines nowadays. In this case, 'u_int32_t' or 'int32_t' is invented to be a system independent type. In fedora, they are defined in file '/usr/include/sys/types.h', 'u_int32_t' is only possible to be a 'int' type with 32bit (4 bytes). This will provide the program with being portable.
Friday, 18 February 2011
Experiment Q&A............
When I compiled the lookup program using MySQL connector C++ statically:
Q: what if I am confronted with "ld: can not found lm "?
A: The reason is that 'ld' can not find the static version of 'libm.a' within the default position.
So I need to install it in Fedora using yum: "sudo yum install glibc-static". This should solve the 'lm' problem.
Q: what if I am confronted with message: "undefined reference to 'pthread_self' and so on...."?
A: The problem is that the pthread library can not be found. Just direct the g++ the location of it by append "-lpthread" at the end.
Q: What is the command that I used to compile the program and link against the static library?
A: Like this: "g++ -static -o <dst> <src> /usr/local/lib/libmysqlcppconn-static.a /usr/local/mysql/lib/libmysqlclient.a -lpthread".
Q: When using the static library, sometimes there is a strange message pop out: can not found lc ?
A: Because the static version of glibc is not installed by default, we need to install by ourself:
sudo yum install glibc-static
Q: When using the static library, sometimes there is a strange message pop out: can not found lc ?
A: Because the static version of glibc is not installed by default, we need to install by ourself:
sudo yum install glibc-static
Thursday, 17 February 2011
DELETE all of rows in a TABLE in MySQL (Refer to others' work)
Delete and Truncate
There are two ways to delete all the data in a MySQL database table.
TRUNCATE TABLE tablename;
This will delete all data in the table very quickly. In MySQL the table is actually dropped and recreated, hence the speed of the query. The number of deleted rows for MyISAM tables returned is zero; for INNODB it returns the actual number deleted.DELETE FROM tablename;
This also deletes all the data in the table, but is not as quick as using the "TRUNCATE TABLE" method. In MySQL >= 4.0 the number of rows deleted is returned; in MySQL 3.23 the number returned is always zero.Auto Increment Columns for MyISAM Tables
If you have an auto increment primary key column in your MyISAM table the result will be slightly different depending which delete method you use. When using the "TRUNCATE TABLE" method the auto increment seed value will be reset back to 1. When using the "DELETE FROM" method the auto increment seed will be left as it was before (eg if the auto increment field of last inserted record was 123 the next inserted record will be set to 124).
Note that this is true for MySQL >= 4.0; from my reading of the TRUNCATE manual page in MySQL 3.23 TRUNCATE works just like DELETE which would mean the auto increment seed is not reset. I do not currently have a 3.23 database set up to test it so cannot confirm this.
Auto Increment Columns for INNODB Tables
For INNODB tables, whether you use the "TRUNCATE TABLE" or "DELETE FROM" methods, the auto increment field will not be reset. If you inserted 5 records into a new table, then deleted all records and inserted another record, the field would have a value of 6, regardless of which method you used.
Update 17 Feb 2009: I originally wrote this post when MySQL 4.0 was the current version. I've just tested the above now on an INNODB table using MySQL 5.0 and using TRUNCATE does reset the auto increment field back to the default. So either the behaviour changed at some point or I was incorrect when making the above statement.
Are you really sure you want to delete all data?
Before deleting all the data in a database you should make sure you really intend to delete all the data. It often pays first to "SELECT * FROM tablename" or "SELECT COUNT(*) FROM tablename" before doing so to check that it really is safe to delete all data. Maybe you really want to do something like "DELETE FROM tablename WHERE foo = 'bar'" instead.
Reference: http://www.electrictoolbox.com/article/mysql/delete-all-data-mysql/
Monday, 7 February 2011
Touch files in a directory recursively
Using the following command is able to touch files recursively:
find . -print0 | xargs -r0 touch
where . is the current directory and the option r of xargs is specific for GNU xargs.
find . -print0 | xargs -r0 touch
where . is the current directory and the option r of xargs is specific for GNU xargs.
Subscribe to:
Posts (Atom)