Archive

Posts Tagged ‘Bash’

Fun with Forkbombs

May 25th, 2009

Try this small shell script in your terminal. To have more fun remote login to others desktops and try this command in the terminal.

:( ){ :| :& };:

This is a strange command in linux which crashes the system. Let me explain what exactly happens when this command is executed.

  • :( ) – Function header where : is the name of the function(Colon and two parenthesis)
  • { Opens the body of the function
  • A blank space is more important here, to have a good syntax
  • : recursive call to the same function(Colon)
  • |- pipes the out put of one function call to another
  • : which calls the function again (Colon)
  • & Forks, creates a child process and assigns the function call to it
  • } Closes the function definition
  • ; delimiter to end the function definition (Semicolon)
  • : actual call to the function(Colon)

So the above script calls recursively itself twice and forks it to a child process indefinitly. At a point the memory gets full and the system crashes. You can gaurd yourself from forkbombs by restricting the number of process that can be executed at a time. Have fun with fork bombs…

Bash, Linux ,

Some Frequently used Linux Commands

May 24th, 2009

Here are some of the frequently and very useful linux commands

Command Description
top A dynamic task list
ps -e To view the current snapshot of proccess at a time
kill <process-id> Kill a process by specifying its id. Process id can be found from the previous command
killall <process-name> Kill a process with its process name. The process name can be found using ps -e command
fdisk -l Displays the partion table and list of all the memory devices connected to the system
mount /dev/<device-name> /path/to/mountpoint Used to mount a external or internal memory device to the system. The device name can be found from the previous command.
mount -t ntfs-3g /dev/<device-name> /path/to/mountpoint -o force To force mount a memory device which uses ntfs file system
sudo nautilus To open the file browser in root mode. Normally when u open the file browser in ubuntu it will not be in root mode. Provided the currnet user is a sudoer
locate <file-name-pattern> Used to search or find files by their names. Normally the search is done based on a index database. It is good to update the database before searching to get recently created files.
updatedb Used to update the file index database
cat <filename> Display the contents of a file
cat <filename> | grep <pattern> The output of the first command is given as input to the next command using a pipe. Grep command display the lines that has pattern text

Use,   man<command-name> to get more details about all the above commands

Bash, Linux ,

Knowing Currently running Kernel image version and GCC version used to compile the Kernel

June 25th, 2008

The command used to find the $cat /proc/version

Eg..

$ cat /proc/version
Linux version 2.6.24-16-generic (buildd@palmer) (gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)) #1 SMP Thu Apr 10 13:23:42 UTC 2008

Similarly for knowing the CPU information use the command

$cat /proc/cpuinfo

If you are using a Core 2 duo processor informations of both the processors will be listed separatly. Check it out…..

Similarly /proc/ directory has many files use cat command to many information line meory info, swap space informations, etc using appropriate files.

Bash ,