显示标签为“Linux”的博文。显示所有博文
显示标签为“Linux”的博文。显示所有博文

2007年6月19日星期二

UNIX Job Control

今天在Emacs里面按了Control-Z,但是我忘了怎样把后台程序弄到前台。
上网查了一下,答案在下面的文章里找到了,原来Control-Z不仅仅对Emacs有效,而是Unix系统里面控制作业进程的通用命令,而将后台的程序调到前台,则需要用%emacs来实现,可以用 jobs 或者 ps查询正在后台执行的作业或进程。
http://www.bu.edu/cc/support/aboutunix/general/jobcontrol/
UNIX Job Control

Any command or any sequence of commands joined by semicolons or by a pipeline is known as a job. Jobs can be suspended and resumed later or they can run "in the background." Background jobs are programs which have been executed in such a way that they return the shell prompt to you while they continue to operate, independent of the shell where they were created. The C shell has a number of built-in functions which enable you to control multiple jobs interactively. Note: running jobs in the background can be useful but may put an excessive load on the system if overused. The 'jobs' command will give you a list of active jobs.

Background and foreground jobs
A program can be run in the background by executing its command line with '&' at the end. For example, you could compile a 'c' program in the background.

% cc other.c -o oter &

%


Then, while the compilation proceeds, you could do some other work, such as edit some files with Emacs.

Later, you might have a new idea and decide that you want to change the source program for your c program to include the new idea. If you don't need the c program to finish its compilation, you could suspend Emacs with ^Z and then stop the compiler by using the kill command.

^Z (Suspend emacs)

Stopped (shell acknowledges)

% jobs

[1] Running cc other.c -o oter (jobs responds)

% kill %1

[1] Killed cc other.c -o oter (kill responds)


While you are at the shell prompt, you could pause to look for mail before resuming emacs:

% mail

No mail for you (mail responds)

% jobs

[1] +Stopped emacs (jobs responds)

% %1 (resume emacs)


In other words, you can resume a job that is stopped by typing %n where 'n' is its job number (the number that the 'jobs' command prints between [ and ]), and you can kill a suspended or stopped job. In fact, if you find yourself caught in a program and don't know how to get out of it, you can suspend the job and then kill it when you get back to the shell prompt. The scope of the 'jobs' command is limited to the shell that it runs under. Job numbers are con- venient references to processes under the control of a single shell.

If you have a job running under another shell that you want to stop, such as at another terminal (for example, you left a job running in the background -- some jobs will keep running), you can use the 'ps' command to find its Process ID (PID, a unique number used by the operating system to identify each process). You can then use the PID to kill the job with the 'kill' command.

% ps

PID TT STAT TIME COMMAND

23444 h4 R 0:00 ps

7158 ic R N 12:33 lisp

%





% kill 7158 (kill a procees by its PID number)

% ps

PID TT STAT TIME COMMAND

23555 h4 R 0:00 ps

%


If you try this method and the job still isn't gone, more drastic methods are needed. Add the -KILL (0r '-9' on some systems) flag as in:

% kill -KILL 7158


No program under UNIX can trap the KILL signal. Just 'kill' sends a -TERM (terminate) signal. This usually works, but if not, -KILL is a sure hit.

Command summary

& run in the background

Z suspend the current job

C interrupt (usually kill) current job

(some programs, such as editors trap

this -- so that a typo won't abruptly

terminate your editing session, losing

your most recent, unsaved work.)



D signal end of input

(log off shell, if issued at top level)



jobs display jobs running from this shell

ps display jobs you are running

ps -g display all jobs and login shells also

kill %n kill a job by job number

kill PID kill a job by process id number

kill -KILL PID a sure kill

('kill -9 PID' on some UNIX versions)


Notes

1. You cannot kill processes you don't own, but you can log in from another terminal and kill a job that has "locked up" your current terminal.
2. Killing your login shell (try 'ps -g') will log you out (Remember, you could force yourself off from a different terminal. When you examine the output of ps, look for the '-csh' commands. If you had an edit session active, you might try 'kill -HUP ###' as that simulates hanging up the 'phone' and most editors will try to preserve interrupted work.)

References
For further information, see the online manual pages or one of the many general books on using the UNIX files system. Information Technology sponsors tutorials on UNIX and other subjects during the academic year and distributes printed handouts on a selection of related subjects.

2007年6月7日星期四

/usr/bin/ld: cannot find -l

使用Linux中的g++处理一个在Windows下的Cygwin的g++可以成功处理的Makefile时,出现了链接库的错误:

g++ a.o -L. -lsqlite3 -o exename
/usr/bin/ld: cannot find -lsqlite3
collect2: ld returned 1 exit status
make: *** [exename] Error 1
这是一个编译时候的路径错误,我把从SQLite官方网站上下载的sqlite3.so放在了Makefile的同目录下。
在 Linux下,默认的链接库的名字为 libsqlite3.so所以我把库名改了。
这时出现如下的错误:
./libsqlite3.so: undefined reference to 'pthread_create'
./libsqlite3.so: undefined reference to 'pthread_getspecific'
./libsqlite3.so: undefined reference to 'dlclose'
./libsqlite3.so: undefined reference to 'pthread_key_create'
./libsqlite3.so: undefined reference to 'dlopen'
./libsqlite3.so: undefined reference to 'dlsym'
./libsqlite3.so: undefined reference to 'pthread_join'
./libsqlite3.so: undefined reference to 'pthread_setspecific'
从SQLite官方网站上下载的这个预编译过的so链接库需要同时链接 libpthread.so
所以命令改为
g++ a.o -lpthread -L. -lsqlite3 -o exename
, 只剩下 dl开头的一些错误。
所以在命令中添加链接库 libdl.so的命令,最后的命令如下
g++ a.o -lpthread -ldl -L. -lsqlite3 -o exename


现在编译链接没有错误了,可以成功生成 exename可执行文件,但可执行文件却有新的错误:
./exename: error while loading shared libraries: libsqlite3.so: cannot open shared object file: No such file or directory.


也就是说,还要把libsqlite3.so这个文件拷贝到/usr/lib中,这个程序才可用。

2007年5月16日星期三

Linux Inside Windows with database support and tomcat

为了推广他们的跨平台产品,这里给出了一个有数据库和网站服务器支持的Windows下的Linux的虚拟机程序。
基于开源的GEMU项目。可以使用按照程序直接完成安装。

http://dev.mainsoft.com/Default.aspx?tabid=49

Using Linux Inside Windows to get started with ASP.NET on Linux

Introduction

If you’re not yet ready to start installing, administering and configuring a full-blown Linux® distro there’s a new alternative called Linux Inside Windows (LIW), and it's available for download from the Grasshopper Web site. LIW will allow you to check out how your Grasshopper applications can run on Linux, while still using your Windows® system.



Figure 1. Running Linux Inside Windows.

LIW is an application based on the QEMU project, which is an open source processor emulator that can be used to run a virtual Linux machine. LIW has taken the QEMU project and added a Debian GNU/Linux system to it, along with Tomcat and PostgreSQL. LIW can happily run applications that you build using Grasshopper. This article describes how to download and install LIW, and then build and run your first J2EE™ application on Linux Inside Windows!

2007年4月26日星期四

SNG(Scriptable Network Graphics)

Linux系统下的在PNG(Portable Network Graphics)与其纯文本格式间转换的工具。
似乎没有windows版本。

2007年4月17日星期二

Xmanager

Xmanager是一个Windows下的链接适用Linux系统的软件(至少今天我作的事情就是这么回事。)
Xstart可以定义一个字符界面的session,进入后启动xterm
Xbrowser可以定义一个图形界面的登录。
等等。