simple examples of how to

Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Monday, November 7, 2011

[Linux] killall by shell script

As the another example of using xargs, you can do the following if your linux box does not have killall.

$ ps ax | grep killme-process | awk '{print $1}' | xargs kill

The above command files the process, killme-process, and kills it.
The chain of pipelining is the following.

First, ps ax gives all the name of processes where the first column is the process ID.
Second, grep killme-process finds the processes with the name, killme-process.
Third, awk only prints the first column ($1) which is the process ID.
Fourth, xargs turns the list of process IDs as the input arguments of kill.
Finally, kill kills them.


Wednesday, November 2, 2011

[Linux] screen simple how to by example

Assume you have 'a remote' and 'a local'.

At the remote, you access via ssh and launch 'screen -S test'.
Then, you will see a terminal-look which is no difference, but in background, there are lot of difference.
First, this terminal-look is not the ssh session that you connect but the session stored in the remote itself (i.e., screen session).
The difference is that although the ssh session dies unexpectedly, screen session does not die.

You can whenever connect this session by screen command.
Here are the most frequently used screen commands

screen -S test (create a new screen session named as 'test')
screen -ls (list the currently created screen sessions)
the results would look like this

16373.test1 (11/03/2011 10:29:08 AM) (Multi, detached)
15342.test2 (11/03/2011 10:30:08 AM) (Multi, attached)

Multi means that multiple attachments are possible.
Attached means that this session is already attached by someone.
If you want to join the attached session, you should use screen -x.
If you want to join the detached session, you should use screen -r.
For example

$ screen -r test1 #reattaching screen session
$ screen -x test2 #attach the currently attached screen session (it looks like a remote desktop of terminal version)
In order to use screen -x, make sure that it is Multi.

At the screen session, if you type 'exit' then the screen session quits.
If you just want to leave the session without quiting it, you type Ctrl+A and d.
it means Detaching from the current screen session.

Thursday, October 20, 2011

[Linux Kernel] What is the main function in Linux kernel ?

In x86 architecture, Linux booting starts with reading MBR (master boot record) into main memory.
The instructions in MBR look up an active partition table and executes a boot loader such as GRUB, LILO, etc.
After users select one of OS, the boot loader loads the selected OS and calls start_kernel() function in "init/main.c" in the Linux kernel source tree.
The terms after the OS name in GRUB (such as ro root=/dev/hda1) are passed to start_kernel() function similar to argc and argv[] in c programs.
That is argv_init variable.