Sharing the development skills of Linux programmer Spence Murray

Source: Internet
Author: User
Tags ftp site imap

Http://hi.baidu.com/xiehongpen/blog/item/113d3f520e2eeb501038c2a9.html

 

Sppence Murray is
He is one of the top Linux developers and has long been a strong supporter of UNIX. This article introduces Murray and his
Consulting's colleagues used the basic technology in daily Linux development and application service work: shell script, believe in Linux
Developers will benefit from this useful and common technology.

Spence Murray is codemonks Consulting
One of the founders of SunOS has been committed to Unix/Linux development since the earliest code written on SunOS in 1980s. Since then
IBM's AIX and sgi irix work to write cross-platform UNIX code for a long time, including
HP/UX, Irix, Solaris/SunOS, sco unix, various BSD, MacOS X, of course, and
Linux. He has done everything from graphics/Video device drivers to UI code. The cross-platform Code Compiled by Murray includes X Window System
Xserver code and core browser code as part of Netscape Navigator.

The most common Linux tools used by Murray are vi, Bash, and Emacs. "Whether I am writing C,
C ++

,
Java

, Shell scripts, or HTML, I switch back and forth among these tools most of the time, "he said.

Linux secret weapon

Murray believes that for a Linux developer, Shell
Is a powerful software development tool, no matter how much evaluation points. "Shell is used in every job I do.
The script can be used to quickly read and modify common text or write code, "he said. "It's lightweight and fast, and its short Command makes moving code back and forth a fast and painless process. As a compilation
It will soon become the second instinct ".

For Murray, emacs emerged later as a development tool. "At 90
In the early days, I tried to use Emacs as an IDE and soon switched to the foyer. Emacs is very powerful. In those days, I will always open an Emacs
Window, usually open dozens of source files, each with the context I edited, the debugging session using GDB, And the bash script running in different source directories. There are many
It can be said that this is a terrible tool... Moreover, you can run Emacs on any system that you want to spend time developing.

VI supported by SunOS for the first time since the middle of 1980s
Since this concise environment, the emacs editor has become a standard tool for Murray. "It is in UNIX of various genres
This is one of the main reasons why I chose cross-platform development, "he said.

Linux developers: Understand your shell

Murray asks you to know your
Shell. "Bash, tcsh, CSH-shell
Is your most basic software development tool, "he stressed. "It can do a lot of amazing things. All work depends on it ...... And its powerful functions ". As a general Shell
An example of powerful script functions is provided in the reference section.
Download

File, which contains a set of scripts for obtaining updates to the RPM software packages issued by Red Hat and merging them into the original software packages and customized software packages.
Download

After the file is decompressed, you can find the script in the/developerworks/rpm_update_scripts directory. The final result is a directory that includes the latest version of all software packages and an hdlist file for network installation upgrades.

The following code snippet implements automatic updates to the Red Hat RPM package to create an installable version that uses the latest rpm. This is for any public Linux
Server

Is a basic step. For us, we usually maintain many public Linux
Server

A large number of network services. The following information is automatically updated to the latest version.
Security

And some scripts of the function process.

The script below demonstrates the normal Shell
Programming technology can be widely used in various system configurations and programming applications. The script uses the Bourne shell, which is the most common in different UNIX systems.
Shell. This ensures that these very lightweight codes can be slightly modified or used on different UNIX systems without modification. Modify Red Hat
It is easy to apply the specification of the software package to other Linux releases.

Freshen. Sh update the RPM package on the site using the specified rpm ftp to update the original RPM list. Execute the filter to replace the updated RPM package. Finally, the long release list is updated based on the new RPM Software Package obtained from the image Update site.

Listing 1. Fresh. Sh
#! /Bin/sh
Rh_ver = $1
Rh_path = $2
Update_dir =$ {rh_path}/Rh $ {rh_ver}-Updates
Custom_dir =$ {rh_path}/Rh $ {rh_ver}-custom
Install_dir =$ {rh_path}/Rh $ {rh_ver}-install
# Sanity check for the original directory.
# Create update and install directories if they don't exist
[-D $ {update_dir}] | mkdir $ {update_dir}
[-D $ {install_dir}/RedHat/RPMS] | mkdir-p $ {install_dir}/RedHat/RPMS
# Get latest updates from fresh RPMs FTP site
./Get_update.sh $ {rh_ver }$ {update_dir}
# Create/update hardlinks from Update, and custom Directories
# To the install directory. We assume that original RPMs are already
# Hardlinked to the install directory, so all we need to do is Filter
# Out Any replaced by updated packages.
./Do-links.sh $ {update_dir }$ {install_dir}/RedHat/RPMS
[-D $ {custom_dir}] &./do-links.sh $ {custom_dir}
$ {Install_dir}/RedHat/RPMS
# Filter out all but the latest version of everything.
/Filter-rpms.pl $ install_dir/RedHat/RPMS
# Rebuild the hard disk lists
/Usr/lib/Anaconda-runtime/genhdlist $ {install_dir}

Freshen. Sh calls the do-links.sh and get_update.sh to set the source, destination (omitted from the source RPM package; hard link used to set the target rpm), and retrieve updates, respectively.

Listing 2. do-links.sh
#! /Bin/sh
Src = $1
DeST = $2
# For file in $ src/*; do
For file in 'Find $ Src-name *. rpm-! -Name *. SRC. rpm-print '; do
Base = 'basename $ file ;'
If test! -F $ DEST/$ base; then
Echo "linking $ file ";
Ln $ File $ dest
Else
Echo "exists: $ file ";
Fi
Done

Listing 3. get_update.sh
#! /Bin/sh
Rh_ver = $1
DeST = $2
Echo "retrieving updates for version $ {rh_ver} to $ DEST"
Lftp <EOF
Open
Ftp.freshrpms.net

<
Ftp://ftp.freshrpms.net

> <
Ftp://ftp.freshrpms.net

>
<
Ftp://ftp.freshrpms.net

>
Mirror-N pub/RedHat/
Linux

/Updates/$ {rh_ver}/en/OS/i386 $ DEST/i386
Mirror-N pub/RedHat/
Linux

/Updates/$ {rh_ver}/en/OS/ies $ DEST/i486
Mirror-N pub/RedHat/Linux/updates/$ {rh_ver}/en/OS/i586 $ DEST/i568
Mirror-N pub/RedHat/Linux/updates/$ {rh_ver}/en/OS/i686 $ DEST/i686
Mirror-N pub/RedHat/Linux/updates/$ {rh_ver}/en/OS/srpms $ DEST/srpms
Mirror-N pub/RedHat/Linux/updates/$ {rh_ver}/en/OS/noarch $ DEST/noarch

Java

And Linux

In codemonks, a lot of development work is to use Java on Linux
Complete. The combination of these two tools provides a platform for creating business-level quality web applications, Murray
. "In the process of doing these projects, we found that we need to understand the customer's existing application code as a whole," he recalled. Locks. C (in
Download

Get
To the/developerworks/locks directory in the compressed file; see references) is a code snippet that is used for Java virtual
Machine profiler interface (jvmpi; reference link for details about jvmpi)
Read/write locks and a large amount of debugging code.

Representatives of Linux developers

"Do not write system-specific code when conditions permit", Murray
But overcome the difficulties to "write the cross-platform code ". The hired Murray insisted that his biggest capital would always be "to write code with commercial quality, to build and provide network services, and to customize the OS"
Or the kernel, and it is completely based on a reliable open source platform ".

The following is a code snippet from a cross-platform custom IMAP server developed by developers of Linux and MacOS X. The Code implements a simple growth cache for processing strings. This avoids cache overflow (do not forget
Security

Vulnerabilities. It is implemented by maintaining a simple variable-length cache, which can be full or cleared. This cache has been used by an IMAP server for an experiment. This server is completed by a team after a week of intense work.

In addition to the implementation of a simple string buffer, this code also implements a variable-Size String Array. It completes a simple interface. After writing a string, you can mark it and continue writing the next one. In addition, this will save space allocation and organize messy Code together.

The complete IMAP server code will be released some time this year.

Listing 4. Part of the custom IMAP Server

# Ifndef hoed_buf_h
# Define hoed_buf_h
Typedef struct {
Char * STR;
Int size;
Int length;
Int str_start;
Int max_size;
Int n_strings;
Int size_strings;
Int * str_posn;
Char ** str_set;
} Hoed_buf_t;
# If _ gnuc _> 2 | (_ gnuc _ = 2 & _ gnuc_minor _> 4)
# Define printf (F, a) _ attribute _ (format (printf, F, )))
# Else
# Define printf (F,)
# Endif
Extern hoed_buf_t * hoed_buf_alloc (INT init_size, int max_size );
Extern void hoed_buf_free (hoed_buf_t *);
Extern void hoed_buf_reset (hoed_buf_t *);
Extern void hoed_buf_new_string (hoed_buf_t *);
Extern char ** hoed_buf_get_set (hoed_buf_t *, int * n_string );
Extern char * hoed_buf_put_char (hoed_buf_t *, char toadd );
Extern char * hoed_buf_sprintf (hoed_buf_t *, const char * format ,...)
Printf (2, 3 );
Extern char * hoed_buf_strcat (hoed_buf_t *, const char * append );
Extern char * hoed_buf_cat_sprintf (hoed_buf_t *, const char * format ,...)
Printf (2, 3 );
# Endif/* hoed_buf_h */

A killer Linux Application

For Murray, there are two killer Linux applications: Emacs and
Netscape Navigator. "Emacs may be the most impressive and widely used Linux-based application," he said. "The other is
Netscape Navigator. Once, we wanted to support more than 20 types of UNIX, and I finished all the work on Linux ".

"Interestingly, Linux-based applications may run on many different Unix systems, or even install cygwin's
Windows

System ."

What is the future of Linux?

Currently, Murray is running Linux
There are several projects, from Distributed Office applications that support email, messages, and shared databases to network applications that use standard tools (standard tools include Apache/tomcat,
PHP, PostgreSQL, MySQL, and Linux ). Murray has his own company dedicated to providing host services for network services and network applications.

For Murray, the list of Linux-powered applications is growing. "There are many," he said. "
Oracle

, Websphere, Apache, PostgreSQL, MySQL, Cyrus IMAP... this list is very long and growing ."

For Murray, this is the end of Linux. "All our servers run
Linux: regardless of the target platform, our main development is on Linux. We recommend Linux to users to run server applications, "he said. "Linux
The pace of rapid development, open source code organization's extensive support for it, low development costs, if you combine these together, you will know that it is an insurmountable platform ".

About the author
John has been working with celebrities in the high-tech field, and he works for CNET, Macromedia, NBCI, Sun Microsystems
Companies such as MSNBC have released products and launched web initiatives. John launched a very creative CNET/Intel project in 1996
Mediadome, and set up shockwave.com of Macromedia in 1998. In 1999, he also created
Media repository house. John serves as a consultant for Sun Microsystem/Netscape's iPlanet
Site prediction and Java-based applications. He is also vice president of standard alliance, a San Francisco ITV.
Application and production companies. You can use
John@mediaoverdrive.com

Contact him.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.