Embedded Linux FAQs

Source: Internet
Author: User
Tags what constant telnet program

Linux Problem Set

1 Linux setting environment variables and where to save

1. Display Environment Variables Home

$ echo $HOME

/home/terry

2. Set a new environment variable welcome

$ exportwelcome= "hello!"

$ echo$welcome

Hello!

3. Use the ENV command to display all environment variables

$ env

hostname=terry.mykms.org

Pvm_rsh=/usr/bin/rsh

Shell=/bin/bash

Term=xterm

histsize=1000

...

4. Use the SET command to display all locally defined shell variables

$ set

Bash=/bin/bash

bash_versinfo= ([0]= "2" [1]= "05b" [2]= "0" [3]= "1" [4]= "Release" [5]= "I386-redhat-linux-gnu")

Bash_version= ' 2.05b.0 (1)-release '

Colors=/etc/dir_colors.xterm

Columns=80

Dirstack= ()

display=:0.0

...

5. Use the unset command to clear environment variables

Set is able to set the value of an environment variable. Clear the value of the environment variable with the unset command.

Assuming that no value is specified, the value of the variable is set to NULL. The scale is as follows:

$ exporttest= "Test ..." #添加一个环境变量TEST

$ env|greptest #此命令有输入 to prove that the environment variable test already exists

Test=test ...

$ unset $TEST # Delete environment variable TEST

$ env|greptest #此命令没有输出 to prove that the environment variable test already exists

6. Use the readonly command to set the read-only variable

Suppose you use the readonly command. The variable cannot be altered or erased.

The scale is as follows:

$ exporttest= "Test ..." #添加一个环境变量TEST

$ readonlytest #将环境变量TEST设为仅仅读

$ unset test# will find that this variable cannot be deleted

-bash:unset:test:cannot unset:readonly Variable

$TEST = "New" #会发现此也变量不能被改动

-bash:test:readonly variable

The global settings for environment variables are located in the/etc/profile file, assuming you need to add a new environment variable to be able to join a subordinate row

Exportpath= $PATH:/path1:/path2:/pahtn

2 Ubuntu Install the Delete command

Apt says it is a advancedpacakge Tool.

Apt-cachesearch Package Search

Apt-cacheshow PackageName Gets the information about the package, such as the version number and size.

Apt-getinstall PackageName installation package.

Apt-getinstall pacekage--reinstall once again installed

Apt-get-finstall PackageName Forced installation

Apt-getremove PackageName Delete a program

Apt-getremove packagename--pure clean off.

Apt-getautoremove self-removal of the package

Apt-getupdate

Apt-getupgrade updating a package that has already been installed

Apt-getdist-upgrade Upgrade the system. No use.

Apt-cachedepends Pacakgename understand the use of dependency, very little use

Apt-cacherdepends PackageName understand the detailed dependencies.

APT-GETBUILD-DEP PackageName Install the relevant compilation environment.

This sometimes needs to be used.

The Apt-getsource package downloads the source code for the packages, which you sometimes need to see when programming

Apt-get Clean

Apt-getautoclean clean up the download file archive.

Apt-getcheck Check for damaged dependencies, very little.

A more specific explanation can be obtained through man apt.

3 How to make Linux self-loading scripts at startup

1 write the script first. For example, the name is a.sh

2 save path is:/etc/rc.d/a.sh

3 Change/etc/rc.d/rc.local

Increase the a.sh script's storage path at the end of the file:/etc/rc.d/a.sh

Save, exit, OK.

4 Mount and the Umount Command

Mount Syntax:

Mount [option]<-t type > [-o mount Options] < device > < mount point >

The-t option is used to specify the type of file system on the partition.

The file system you encounter most often should be EXT2FS (gnu/linux file system) or EXT3FS (improved log performance ext2fs), VFAT (for all dos/windows? Partitions: FAT12, + or 32) and ISO9660 ( CD-ROM file system). Assuming that you do not specify any type, mount will attempt to read the chunks in the partition to extrapolate the filesystem.

The-o option specifies one or more mount options. The options you choose vary depending on the file system type. Take a look at the details in the Mount (8) manual page. Typically, a partition is mounted on a/mnt or other mount point (the mount point must already exist).

Example:

$ mount-text3/dev/hdb1/mnt

The partition to be removed. You can use the Umount command. Grammar:

Umount < mount points | equipment >

Example:

$ UMOUNT/MNT OR:

$ umount/dev/hdb1

Tip: Some devices (usually CD-ROM) may be busy or unresponsive at some point. At this point, the workaround for most users is to start the computer again.

We don't have to do this. Suppose, for example, that UMOUNT/DEV/HDC fails. You can try "lazy" umount. The syntax is simple:

umount-l< mount point | equipment >

This command disconnects the device and closes all handles that open the device. Typically, you can use the eject < mount point | device > Command to eject the disc. So, suppose the eject command fails and you don't want to start again. Please use the lazy umount.

Suppose that we want the system to mount some partitions on its own when it is started, you should edit the/etc/fstab file. Each line of the file corresponds to a set of mount relationships, including the file system, mount point, and other options. Here is a sample of the file:

/DEV/HDA1/EXT2 Defaults 1 1

/dev/hda5/home ext2 Defaults 1 2

/dev/hda6 swap swap defaults 0 0

None/mnt/cdrom supermount Dev=/dev/scd0,fs=udf:iso9660,ro,--0 0

None/mnt/floppy supermountdev=/dev/fd0,fs=ext2:vfat,--, sync,umask=0 0 0

NONE/PROC proc Defaults 0 0

None/dev/pts devpts mode=0622 0 0

Each row is made up of the following:

The device on which the file system resides;

mount point;

File system type;

Mount option;

Dump tool backup flag ;

The check order of fsck (file system check) FileSystem.

There is always a row explaining the root file system. The swap partition is a special partition, because you cannot find its corresponding location in the tree structure, and the mount point fields of those partitions are only written with swap keyword. As for the/proc file system. We will have more specific descriptive narratives in the 10th Chapter/proc File System . The second special file system is/dev/pts.

A sample example. Assuming that you want to mount/dev/hdb1 yourself to/usr, you have to add the following line to the/etc/fstab file:

/DEV/HDB1/USR ext2 Defaults 1 2

This way, the partition will be mounted on its own initiative each time it is started. And, if necessary, check for errors.

Now let's introduce two special options: Noauto and user. The Noauto option specifies that the file system should not be mounted at startup. It should only be mounted when you want to mount it.

The user option specifies that the file system can be mounted or removed, regardless of users. These two options are often used for CD-ROM and floppy disk drives. More about the other options in/etc/fstab. Please view the Fstab (5) manual page.

The advantage of using/etc/fstab is that. It will greatly simplify the syntax of the Mount command. To mount the file system describing the narrative in the file. You only need to refer to a mount point or device.

To mount a floppy disk, you can simply enter:

$ mount/mnt/floppy

Or:

$ mount/dev/fd0

5 file Lock Problem

Q: Using FCNTL to lock a file, add a file to a process multiple times with the same type of lock. Don't you get an error?

A: Suppose a process has a lock on a file interval, and then the process attempts to add another lock to the same file range, the new lock replaces the old lock.

6 framebuffer Simple Introduction

FrameBuffer is one of the driver interfaces in today's 2.2.xx kernel. Such an interface will show the device abstraction as a frame buffer.

The user can view it as an image of the display memory, after mapping it to the process address space. Can be read and written directly, and the write operation can be immediately reflected on the screen. The driver's device files are usually/dev/fb0,/DEV/FB1, and so on.

For example, if today's display mode is a 1024x768-8 bit color, you can clear the screen with commands such as the following:

$ dd If=/dev/zero of=/dev/fb0 bs=1024 count=768

In the application. This is typically done by mapping the FrameBuffer device to the process address space, for example, the following program opens the/DEV/FB0 device and addresses it through mmap system calls, then empties the screen with memset (where the display mode is 1024x768-8 bit color mode , linear memory Mode):

int FB;

unsigned char* fb_mem;

FB = open ("/dev/fb0", O_RDWR);

Fb_mem = Mmap (NULL, 1024*768,prot_read| prot_write,map_shared,fb,0);

memset (fb_mem, 0, 1024x768);

The FrameBuffer device also provides several IOCTL commands that enable you to obtain some fixed information about the display device (such as the memory size), variable information related to the display mode (for example, resolution, pixel structure, byte width per scan line), and color palette information in pseudo-color mode, and so on.

With the FrameBuffer device, you can also get the type of accelerated display card supported by the current kernel (via fixed information). Such a type is usually associated with a particular display chip. For example, the latest kernel (2.4.9) includes accelerated support for S3, Matrox, NVidia, 3Dfx, and other popular display chips. After the accelerated chip type has been obtained, the application is able to map the PCI device's memory I/O (Memio) to the process's address space.

These memio are usually used to control the registers of the display card, and by manipulating these registers, the application can control the acceleration of a particular graphics card.

PCI devices can map their control registers to physical memory space, and then access to these control registers becomes an access to physical memory. So. These registers are also called "Memio". Once it is mapped to physical memory. The normal process of Linux is able to map these memory I/O to the process address space through mmap, so that the registers can be directly interviewed.

Of course, because different display chips have different acceleration capabilities. The use and definition of Memio are different, at this point, it is necessary to speed up the different types of chip to achieve different acceleration functions. For example, most chips provide hardware acceleration support for rectangular fills, but different implementations of the chip are different. At this point, you need to write different functions for filling the rectangle for different chip types.

In this case, the reader may have realized that FrameBuffer is simply a device that provides display memory and a display chip register that is mapped from physical memory to the process address space. So, for an application, suppose you want to do graphical programming on top of framebuffer. A lot of other work is needed. Give me a sample. FrameBuffer is like a canvas, use what kind of brush, how to draw. You need to finish it yourself.

7 Strings role of the command

Some files in binary format.

You want to know what constant strings are in there.

It's very practical. For example, you generate such a program, A.C:

int main (void)

{

return printf ("Hello world\n");

}

#cc-o A.OUTA.C

#strings./a.out

/lib64/ld-linux-x86-64.so.2

_jv_registerclasses_

_gmon_start_

_

Libc.so.6

Printf

__libc_start_main

glibc_2.2.5

Hello World

8 What is A tty?

Terminal equipment is a type of character device. It is available in a variety of types and is commonly referred to as TTY. TTY is the abbreviation for teletype. Teletype is one of the first terminal equipment, very much like a telex typewriter (or is it?).

)。 It is produced by Teletype company. Under the Device Special Files folder/dev/of the Linux system. End-device files generally have the following types:

1. End-of-string terminal (/DEV/TTYSN)

The serial port terminal (Serial Port Terminal) is a terminal device that uses a computer serial port connection. The computer sees every serial port as a character device. For a while, these serial port devices are often referred to as terminal equipment, since it is used to connect the terminals for the maximum purpose. The serial port corresponding device name is/dev/tts/0 (or/DEV/TTYS0),/DEV/TTS/1 (or/dev/ttys1), etc., the device number is (4,0), (4,1), respectively, corresponding to the DOS system COM1, COM2 and so on. To send data to a port, you can redirect standard output to these special file names on the command line. For example, at the command-line prompt, type: echotest >/dev/ttys1 will send the word "test" to the device connected to Port TtyS1 (COM2).

2. Pseudo-terminal (/dev/pty/)

Pseudo-terminal (Pseudo Terminal) is a paired logical terminal device. such as/DEV/PTYP3 and/DEV/TTYP3 (or/dev/pty/m3 and/DEV/PTY/S3 in the device file system). They are not directly related to the actual physical device. Suppose a program considers TTYP3 as a serial port device, then its read/write operation on the port is reflected in the pair of the logical terminal (PTYP3). PTYP3 is a logical device that has a program for read and write operations.

In this way, two programs are able to communicate with each other through such a logical device. One of the programs that uses TTYP3 feels like it is communicating with a serial port. This is very much like a pipe operation between logical device pairs.

For TTYP3 (S3), any program designed to use a serial port device can use the logical device. For programs that use PTYP3, however, they need to be specifically designed to use PTYP3 (m3) logic devices.

For example, if someone uses a Telnet program on the Internet to connect to your computer, the Telnet program may start connecting to the device Ptyp2 (m2) (a pseudo terminal port).

At this point a Getty program should be executed on the corresponding TTYP2 (S2) port.

When Telnet obtains a character from the far end. The character is passed to the Getty program via M2, S2, and the Getty program returns the "login:" String information to the network via S2, M2, and Telnet programs. In this way, the login program communicates with the Telnet program through a "pseudo-terminal". By using the appropriate software, two or more pseudo-terminal devices can be connected to the same physical serial port.

Before using device filesystem, a complex file name naming method was used to obtain a large number of special files for pseudo-terminal devices. Because there are only 16 Ttyp (TTYP0-TTYPF) of the device files, in order to get a lot of other logical device pair, it uses like Q, R, S and other characters to replace P. Like what. Ttys8 and Ptys8 are a pseudo-terminal device pair.

Just this naming method is still used in Linux systems such as Redhat.

However, Unix98 on a Linux system does not use this method. The "Pty Master" approach was used, such as/DEV/PTM3. Its corresponding end will be self-initiated to create a/DEV/PTS/3. This makes it possible to provide a Pty pseudo terminal when needed. Folder/dev/pts is a file system of type devpts. And can be seen in the list of files that are loaded into the file system.

Although the file/DEV/PTS/3 appears to be an item in the device file system, it is in fact a completely different file system.

3. Control Terminal (/dev/tty)

Assume that the current process has a control terminal (controlling Terminal). Then/dev/tty is the device special file of the current Process Control terminal.

You can use the command "Ps–ax" to see which control terminal the process is connected to.

For your login Shell,/dev/tty is the terminal you use, the device number is (5,0). Use the command "TTY" to see which actual terminal device it is in detail. /dev/tty somewhat resembles a join or alias to a terminal device that is actually used.

4. Console (/dev/ttyn,/dev/console)

In the Linux system. A computer monitor is often referred to as a console terminal or a console (console).

It simulates a terminal (term=linux) of type Linux. And there are some equipment special files associated with it: Tty0, Tty1, Tty2 and so on. When you log in on the console, you are using Tty1.

When using the ALT+[F1-F6] key combination. We will be able to switch to Tty2, Tty3 and so on. Tty1–tty6 is called a virtual terminal, and Tty0 is an alias of the virtual terminal that is currently used, and the information generated by the Linux system is sent to that terminal.

So regardless of which virtual terminal we are currently using, the system information will be sent to our screen. C} $k]\

You can log on to different virtual terminals so that you can have several different sessions in the system at the same time. However, only the system or Superuser root can write to/dev/tty0, and sometimes the/dev/console is connected to/dev/tty0 or/dev/tty1.

5. Other types

The Linux system also has a very large number of other types of terminal equipment special files for very many different character devices.

For example,/dev/ttyin terminal equipment for ISDN devices. Don't repeat it here.

9 NM command and Strip command

The NM command displays the object file, the executable file, and the symbol information in the object file library.

The Strip command reduces the size of the Xcoff object file. The Strip command selectively removes line number information, reposition information, debug segments, Typchk segments, gaze segments, file headers, and all or part of the symbol table from the XCOFF object file.

Once you use this command, it is very difficult to debug the symbols of the file. Therefore, you should usually only use the strip command on a build module that has been debugged and tested. Use the Strip command to reduce the amount of storage overhead required for an object file.

Embedded Linux FAQs

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.