Wednesday, 11 January 2017

How to reverse Singly Linked List?

Program: How to reverse Singly Linked List?


Description:
Write a sample code to reverse Singly Linked List by iterating through it only once.

Recursive Method:
 1) Divide the list in two parts - first node and rest of the linked list.
 2) Call reverse for the rest of the linked list.
 3) Link rest to first.
 4) Fix head pointer.

Code:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.java2novice.ds.linkedlist;
  
public class SinglyLinkedListImpl<T> {
  
    private Node<T> head;
      
    public void add(T element){
          
        Node<T> nd = new Node<T>();
        nd.setValue(element);
        System.out.println("Adding: "+element);
        Node<T> tmp = head;
        while(true){
            if(tmp == null){
                //since there is only one element, both head and
                //tail points to the same object.
                head = nd;
                break;
            } else if(tmp.getNextRef() == null){
                tmp.setNextRef(nd);
                break;
            } else {
                tmp = tmp.getNextRef();
            }
        }
    }
      
    public void traverse(){
          
        Node<T> tmp = head;
        while(true){
            if(tmp == null){
                break;
            }
            System.out.print(tmp.getValue()+"\t");
            tmp = tmp.getNextRef();
        }
    }
     
    public void reverse(){
         
        System.out.println("\nreversing the linked list\n");
        Node<T> prev = null;
        Node<T> current = head;
        Node<T> next = null;
        while(current != null){
            next = current.getNextRef();
            current.setNextRef(prev);
            prev = current;
            current = next;
        }
        head = prev;
    }
     
    public static void main(String a[]){
        SinglyLinkedListImpl<Integer> sl = new SinglyLinkedListImpl<Integer>();
        sl.add(3);
        sl.add(32);
        sl.add(54);
        sl.add(89);
        System.out.println();
        sl.traverse();
        System.out.println();
        sl.reverse();
        sl.traverse();
    }
}
  
class Node<T> implements Comparable<T> {
      
    private T value;
    private Node<T> nextRef;
      
    public T getValue() {
        return value;
    }
    public void setValue(T value) {
        this.value = value;
    }
    public Node<T> getNextRef() {
        return nextRef;
    }
    public void setNextRef(Node<T> ref) {
        this.nextRef = ref;
    }
    @Override
    public int compareTo(T arg) {
        if(arg == this.value){
            return 0;
        } else {
            return 1;
        }
    }
}

Output:
Adding: 3
Adding: 32
Adding: 54
Adding: 89

3 32 54 89 

reversing the linked list

89 54 32 3 
- See more at: http://www.java2novice.com/java-interview-programs/revese-singly-linked-list/#sthash.wLLhBX8C.dpuf

Java Interview Programs List For Beginners




List Of All Interview Programs:

  1. How to reverse Singly Linked List?
  2. Find out duplicate number between 1 to N numbers.
  3.  
  4. Find out middle index where sum of both ends are equal.

  5. Write a singleton class.

  6. Write a program to create deadlock between two threads.


  7. Write a program to reverse a string using recursive algorithm.

  8. Write a program to reverse a number.

  9. Write a program to convert decimal number to binary format.

  10. Write a program to find perfect number or not.

  11. Write a program to implement ArrayList.

  12. Write a program to find maximum repeated words from a file.

  13. Wrie a program to find out duplicate characters in a string.

  14. Write a program to find top two maximum numbers in a array.

  15. Write a program to sort a map by value.

  16. Write a program to find common elements between two arrays.

  17. How to swap two numbers without using temporary variable?

  18. Write a program to print fibonacci series.

  19. Write a program to find sum of each digit in the given number using recursion.

  20. Write a program to check the given number is a prime number or not?

  21. Write a program to find the given number is Armstrong number or not?

  22. Write a program to convert binary to decimal number.

  23. Write a program to check the given number is binary number or not?

  24. Write a program for Bubble Sort in java.

  25. Write a program for Insertion Sort in java.

  26. Write a program to implement hashcode and equals.

  27. How to get distinct elements from an array by avoiding duplicate elements?

  28. Write a program to get distinct word list from the given file.

  29. Write a program to get a line with max word count from the given file.

  30. Write a program to convert string to number without using Integer.parseInt() method.

  31. Write a program to find two lines with max characters in descending order.

  32. Write a program to find the sum of the first 1000 prime numbers.

  33. Find longest substring without repeating characters.

  34. Write a program to remove duplicates from sorted array.

  35. How to sort a Stack using a temporary Stack?

Apache on CentOS Linux For Beginners



Install Apache in the usual way with Yum, set it to automatically start at boot, and then start it:

$ sudo yum -y install httpd
$ sudo systemctl enable httpd.service
$ sudo systemctl start httpd.service
Point a web browser to http://localhost, and you should see a test page (Figure 1).

apache-test-page.png

Apache test page
Figure 1: Apache test page.

It works! We are wonderful.

SELinux

CentOS installs with an active SELinux configuration set to SELINUX=enforcing in /etc/sysconfig/selinux, which will prevent your new virtual hosts from operating. There are two ways to handle this. One way is to disable SELinux by changing SELINUX=enforcing to SELINUX=permissive, and then rebooting. This keeps your rules active without enforcing them, and logs all SELinux messages so you can study how the rules are working, and if they are set correctly.
The other way is to leave SELinux in enforcing mode and create a ruleset for your new virtual host. In the following examples our virtual host root is /var/www/html/mysite.com:

$ sudo semanage fcontext -a -t httpd_sys_rw_content_t \
  '/var/www/html/mysite.com(/.*)?'
restorecon -RF /var/www/html/mysite.com
While you're testing and learning, you could make this ruleset apply to your entire web root by using '/var/www/html(/.*)?' instead of creating rules for each individual virtual host. Note that neither of these rulesets are very secure; they're for making testing easier. A more secure SELinux configuration is more fine-grained and applied to individual directories; I leave it as your homework to study how to do this.

Configuration Files

CentOS/etc. use a different configuration file structure than the Debian Linux family. Apache configuration files are stored in /etc/httpd. The default CentOS 7 installation supplies these directories:

conf
conf.d
conf.modules.d
logs
modules
run
conf contains the main server configuration file, httpd.conf. You probably won't edit this file very often. This contains global configurations such as the location of the configuration files, include files, the Apache user and group, document root, and log file location and format.
conf.d is where your virtual hosts and any other custom configurations go. It contains welcome.conf, which is is the default virtual host that displays the default welcome page. autoindex.conf enables directory listings, and php.conf controls how Apache interacts with PHP.
All files in conf.d must have a .conf extension. This is controlled in httpd.conf, so you have the option to change it to whatever you want. Really. Even something goofy, like .feedme or .hiapache.
conf.modules.d loads whatever installed modules you want to use.
logsmodules, and run are all symlinks to other directories. Take a little time to study your configuration files and see what is in them.

Create a new virtual host

Now that we have an inkling of what to do, let's create a new virtual host and its welcome page. In this example it is mysite.com.

$ sudo mkdir -p /var/www/html/mysite.com
$ cd /var/www/html/test.com
$ sudo nano index.html

You are welcome to copy this fabulous custom welcome page:

<head>
<title>Mysite.com index page</title>
</head>
<h1>Hello, welcome to mysite.com! It works!</h1>            
<h2>That is all I have to say. If you don't 
see this then it doesn't work.</h2>
</body>
</html>
Test your new index page by opening it in a web browser (Figure 2), which in this example is file:///var/www/html/mysite.com/index.html.

mysite-test-page.png

Mysite test page
Figure 2: Mysite test page.
Excellent, the welcome page renders correctly. Now let's configure a virtual host to serve it up, /etc/httpd/conf.d/mysite.conf.

$ cd /etc/httpd/conf.d/
$ sudo nano mysite.conf
This is a basic barebones virtual host:

<VirtualHost *:80>
    ServerAdmin carla@localhost
    DocumentRoot /var/www/html/mysite.com
    ServerName mysite.com
    ServerAlias mysite.com
</VirtualHost>
Now point a web browser to http://localhost/mysite.com to (Figure 3).

mysite-test-page-2.png

Mysite virtual host
Figure 3: Mysite virtual host.
Behold! Your fab new virtual host lives! If it doesn't look right restart Apache, and force your browser to bypass its cache by pressing Shift+reload. After years of testing multiple setups and running Apache on all kinds of Linux distributions, I'm rather muddled on when you need to restart or reload the configuration without restarting, or when Apache picks up new configurations automatically. During your testing, you can restart it with gay abandon.

Multiple virtual hosts

For quick easy testing map your server's IP address to your domain names in /etc/hosts:

192.168.1.25       mysite.com
192.168.1.25       www.mysite.com
Now you can access http://mysite.com and http://www.mysite.com without the localhost portion of the address. Copy these /etc/hosts entries to other hosts on your LAN, and they should also have access to your site.
To set up more sites repeat these steps, creating different document roots and domains for each one, and their corresponding entries in /etc/hosts. For example, adding second virtual host looks like this:

192.168.1.25       mysite.com
192.168.1.25       www.mysite.com
192.168.1.25       mycatpics.com
192.168.1.25       www.mycatpics.com
And beware of SELinux.
When you're ready to roll out a production server refer to Dnsmasq For Easy LAN Name Services to learn how to set up DNS on your LAN with the excellent Dnsmasq name server.
Creating a publicly accessible Internet web server is a much bigger job that involves registering domain names, setting up careful and correct DNS, and building a good firewall. Do please study this with great care.
The fine Apache documentation is exhaustively thorough, and it makes more sense when you have a live server running, and have some idea of how things work
source: linux.com.

Tuesday, 10 January 2017

How To Install Proprietary Graphics Drivers In Ubuntu & Fedora [Linux]


Being a Linux user lets you have a pretty cool choice – open source or proprietary software. While a lot of die-hard Linux users will scream at you if you use anything proprietary (and I recommend not using proprietary software unless absolutely necessary, but that’s still your choice), you can still install whatever the heck you want.
There are a good amount of proprietary products that are being made available for Linux, both free and paid, and they aren’t going away anytime soon. But because Linux allows the best of both worlds, you may also be curious about the proprietary drivers that are available.

Why Do You Possibly Need Proprietary Drivers?

In virtually all distributions, only open source drivers that come with the Linux kernel are used out of the box. While this should be perfectly fine for simple use (and it should work on any graphics setup), AMD and nVidia users may still feel the need to use the more powerful proprietary drivers so that games, videos, and more all play as smoothly as possible.
Intel users shouldn’t feel left out. Intel doesn’t offer any proprietary drivers, but instead pushes all of its work directly to its only set of graphics drivers, which are open source and included with the kernel.


Ubuntu

ubuntu graphics driver

Ubuntu users have the easier route to getting these drivers installed. You’ll simply need to open your dash, menu, etc. and look for the Additional Drivers application. This little program will look to see if you have any hardware in your system that could be better supported through proprietary drivers. While it may also include wireless drivers, this is usually the place for the proprietary graphics drivers.

Simply click on which you’d like to install (I’d usually go with the latest), and apply.


If you like a more technical route, you can technically find the fglrx package for AMD cards and nvidia-glx-xxx for nVidia cards (where xxx is the version number, like 185), but I recommend using the Additional Drivers application as it takes care of everything, and I’ve run into problems just installing fglrx through the package manager instead of through Additional Drivers.

Fedora

ubuntu graphics driver

Fedora users have it a little more difficult, but it’s very manageable. First, you’ll need to head over to this site and install the free and non-free packages for your version of Fedora. These packages will add information about the repository which hosts the proprietary drivers, as the default repositories of Fedora are open-source only. Once that completes, you should now be able to search for kmod-catalyst for AMD cards or kmod-nvidia for nVidia cards.
This is a package that keeps track of dependencies and kernel modules, so whenever you install a new kernel it’ll update the drivers as well. Install, restart, and you’re up and running!
source: makeuseof.com

The Reasons Why We Use Linux Kill Signals And Commands




Kill Commands
The kill commands (such as kill, xkill, etc.) are commands that use the the "kill()" system call. In other words, the command-line kill commands are wrappers for the kernel's "kill()" syscall.

kill
The kill command will kill a process using the kill signal and PID given by the user. To use the SIGKILL signal with "kill", type one of the following for a process with a PID of 1710.
Code:
kill -9 1710
kill -SIGKILL 1710
kill -KILL 1710

The kill command accepts either the signal number, partial name (omitting “SIG”) or name (signals have both a number and name that can be referenced). The name must be in all caps. However, some systems do not support partial names.

killall
The killall command kills all process with a particular name. For instance, Nautilus may be running several times. To kill all of them type "killall -SIGQUIT nautilus". Also, if Firefox is running once and the user does not know the PID, use the killall command - "killall -9 firefox". The killall command also uses case-sensitive kill signals (they are all uppercase). Below demonstrates what will happen when the kill signal is typed in lowercase. Notice that the command uses the "s" as a parameter and then it does not know what to do with the rest of the information. It then tries to use "igkill" as a kill signal, but no such signal exists.
Code:
collier@Nacho-Laptop:~$ killall -sigkill nautilus
igkill: unknown signal; killall -l lists signals.
pkill
This command is a lot like killall except it allows partial names. So, "pkill -9 unity" will kill any process whose name begins with "unity". pkill can also kill all processes owned by a particular user - “pkill -9 -u USERNAME”


xkill
This command allows users to kill a command by clicking the window. This kill command is offered by the X Server and is only usable on systems using X11. In a terminal, type "xkill" and then the cursor will change. Next, click a window to kill. The application should disappear and leave the system's memory. Then, the cursor will return to normal. Alternate display servers (like Weston and Mir) do not support xkill and do not have equivalents (at this time).

Signals
There are many kill signals that each serve a particular purpose. Typing "kill -l" will list the kill signals supported by that particular utility (explained in a moment). Notice that all kill signals begin with "SIG"; this means SIGnal.

Code:
kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL
5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE
9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2
13) SIGPIPE 14) SIGALRM 15) SIGTERM 17) SIGCHLD
18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN
22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO
30) SIGPWR 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1
36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4 39) SIGRTMIN+5
40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+9
44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13
52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9
56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5
60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 63) SIGRTMAX-1
64) SIGRTMAX
Yes, certain numbers are missing because those signals are not supported on my system or by that kill command, or they were discontinued. If you run the same command, you may have different numbers missing/available.

Here is a typically unknown trick. Many shells (such as BASH) have their own kill command that is separate from the system's kill command (/bin/kill). To see this on a system, type "kill -l", "kill -L", "/bin/kill -l", and "/bin/kill -L" in a terminal one at a time. It can be seen that the results are different between kill and /bin/kill. There are some signals and parameters supported by one and not the other. However, everyone has SIGHUP (1), SIGQUIT (3), SIGKILL (9), and SIGTERM (15). Those are the most common and useful signals. It is important to learn and memorize those four very well when administering Linux systems.

Kill-Signal-List.png 

Kill signals are not only used to close locked-up applications, but also stop software from performing unallowed tasks. This means some of these kill signals are part of security. Surprisingly, kill commands not only stop/kill processes but they also pause, continue, and restart processes.

A list of signals supported by the kernel can be found in /usr/include/linux/signal.h. This file may show that the signals come from two assembly libraries (/usr/include/asm/signal.h and /usr/include/asm/siginfo.h).

Signal Descriptions
NOTE: This is alphabetically sorted.
  • SIGABRT - This kill signal is the abort signal. Typically, a process will initiate this kill signal on itself.
  • SIGALRM - SIGALRM is sent when the real-time or clock-time timer expires.
  • SIGBUS - When a process is sent the SIGBUS signal, it is because the process caused a bus error. Commonly, these bus errors are due to a process trying to use fake physical addresses or the process has its memory alignment set incorrectly.
  • SIGCHLD - When a parent process loses its child process, the parent process is sent the SIGCHLD signal. This cleans up resources used by the child process. In computers, a child process is a process started by another process know as a parent.
  • SIGCONT - To make processes continue executing after being paused by the SIGTSTP or SIGSTOP signal, send the SIGCONT signal to the paused process. This is the CONTinue SIGnal. This signal is beneficial to Unix job control (executing background tasks).
  • SIGEMT - Processes receive this signal when an emulator trap occurs.
  • SIGFPE - Processes that divide by zero are killed using SIGFPE. Imagine if humans got the death penalty for such math. NOTE: The author of this article was recently taken out to the street and shot for dividing by zero. (^u^)
  • SIGHUP - The SIGHUP signal disconnects a process from the parent process. This an also be used to restart processes. For example, "killall -SIGHUP compiz" will restart Compiz. This is useful for daemons with memory leaks.
  • SIGILL - When a process performs a faulty, forbidden, or unknown function, the system sends the SIGILL signal to the process. This is the “ILLegal SIGnal”.
  • SIGINFO - Terminals may sometimes send status requests to processes. When this happens, processes will also receive this signal.
  • SIGINT - This signal is the same as pressing ctrl-c. On some systems, "delete" + "break" sends the same signal to the process. The process is interrupted and stopped. However, the process can ignore this signal.
  • SIGIO - An alias to SIGPOLL.
  • SIGIOT - This is an alias for SIGABRT.
  • SIGKILL - The SIGKILL signal forces the process to stop executing immediately. The program cannot ignore this signal. This process does not get to clean-up either.
  • SIGLOST - Processes trying to access locked files will get this signal. Many systems use SIGLOST as an alias for SIGPOLL especially since accessing locked files is an asynchronous I/O event.
  • SIGPIPE - When a process tries to write to a pipe that lacks an end connected to a reader, this signal is sent to the process. A reader is a process that reads data at the end of a pipe.
  • SIGPOLL - When a process causes an asynchronous I/O event, that process is sent the SIGPOLL signal. SIGPOLL and SIGIO are aliases. In the assembly source code, SIGIO is defined as "29" and SIGPOLL is defined as "SIGIO".
  • SIGPROF - SIGPROF is sent when CPU time used by the process and by the system on behalf of the process elapses.
  • SIGPWR - Power failures will cause the system to send this signal to processes (if the system is still on).
  • SIGQUIT - This is like SIGINT with the ability to make the process produce a core dump.
  • SIGRTMAX* - This is a set of signals that varies between systems. They are labeled SIGRTMAX-1, SIGRTMAX-2, SIGRTMAX-3, ......., and so on (usually up to 14). These are user-defined signals; they must be programmed in the Linux kernel's source code. That would require the user to know C/C++.
  • SIGRTMIN* - This is a set of signals that varies between systems. They are labeled SIGRTMIN+1, SIGRTMIN+2, SIGRTMIN+3, ......., and so on (usually up to 15). These are user-defined signals; they must be programmed in the Linux kernel's source code. That would require the user to know C/C++.
  • SIGSEGV - When an application has a segmentation violation, this signal is sent to the process.
  • SIGSTOP - This signal makes the operating system pause a process's execution. The process cannot ignore the signal.
  • SIGSYS - Processes that give a system call an invalid parameter will receive this signal.
  • SIGTERM - This signal requests a process to stop running. This signal can be ignored. The process is given time to gracefully shutdown. When a program gracefully shuts down, that means it is given time to save its progress and release resources. In other words, it is not forced to stop. SIGINT is very similar to SIGTERM.
  • SIGTRAP - This signal is used for debugging purposes. When a process has performed an action or a condition is met that a debugger is waiting for, this signal will be sent to the process.
  • SIGTSTP - This signal is like pressing ctrl-z. This makes a request to the terminal containing the process to ask the process to stop temporarily. The process can ignore the request.
  • SIGTTIN - When a process attempts to read from a tty (computer terminal), the process receives this signal.
  • SIGTTOU - When a process attempts to write from a tty (computer terminal), the process receives this signal.
  • SIGUNUSED - On many systems, this is an alias for SIGSYS.
  • SIGURG - When a process has urgent data to be read or the data is very large, the SIGURG signal is sent to the process.
  • SIGUSR1 - This indicates a user-defined condition. This signal can be set by the user by programming the commands in sigusr1.c. This requires the programmer to know C/C++.
  • SIGUSR2 - This indicates a user-defined condition.
  • SIGVTALRM - SIGVTALRM is sent when CPU time used by the process elapses.
  • SIGWINCH - When a process is in a terminal that changes its size, the process receives this signal.
  • SIGXCPU - When a process uses the CPU past the allotted time, the system sends the process this signal. SIGXCPU acts like a warning; the process has time to save the progress (if possible) and close before the system kills the process with SIGKILL.
  • SIGXFSZ - Filesystems have a limit to how large a file can be made. When a program tries to violate this limit, the system will send that process the SIGXFSZ signal.

Signals Defined in /usr/include/asm/signal.h (Linux 3.19.0-21-generic)
Code:
#define SIGHUP  1
#define SIGINT  2
#define SIGQUIT  3
#define SIGILL  4
#define SIGTRAP  5
#define SIGABRT  6
#define SIGIOT  6
#define SIGBUS  7
#define SIGFPE  8
#define SIGKILL  9
#define SIGUSR1  10
#define SIGSEGV  11
#define SIGUSR2  12
#define SIGPIPE  13
#define SIGALRM  14
#define SIGTERM  15
#define SIGSTKFLT  16
#define SIGCHLD  17
#define SIGCONT  18
#define SIGSTOP  19
#define SIGTSTP  20
#define SIGTTIN  21
#define SIGTTOU  22
#define SIGURG  23
#define SIGXCPU  24
#define SIGXFSZ  25
#define SIGVTALRM  26
#define SIGPROF  27
#define SIGWINCH  28
#define SIGIO  29
#define SIGPOLL  SIGIO
/*#define SIGLOST  29*/
#define SIGPWR  30
#define SIGSYS  31
#define SIGUNUSED  31
Users can use these kill signals using one of the many kill commands, such as pkill, xkill, etc. (if supported). When sending a signal to a process owned by another user (like Root), the user needs admin privileges and must use the sudo command. Be careful though, misuse of these signals can cause system damage. For instance, using SIGTERM on a GUI process like Compiz, X11, XFCE, Unity, Gnome-shell, etc. will make the system unviewable. However, some GUI processes will turn back on.

NOTE: If Compiz or some other important GUI utility freezes, crashes, etc., use SIGHUP to restart the GUI.

The Zero Signal
There is another signal that is supported by most systems, but is not list in the "kill -l" command. This is the "0" signal which is called "SIGT". This signal is used to see if the user can send signals to the specified PID/process. For instance, if a user owns a process and the process is running, then the command "kill -0 PID" will return "0". However, if the user does not own the specified PID or the PID is not assigned to a process, then the return value is "1".

Not all systems and kill commands support "0" or support it properly. For instance, on Ubuntu 15.04 (Vivid Vervet), the signal "0" and "SIGT" do not work with the "kill" command supplied by Bash or "/bin/kill".
Code:
collier@Nacho-Linux:~$ pidof firefox
21609
collier@Nacho-Linux:~$ /bin/kill 0 21609
Terminated
collier@Nacho-Linux:~$ /bin/kill SIGT 21609
kill: failed to parse argument: 'SIGT'
collier@Nacho-Linux:~$ kill 0 21609 # This killed Firefox
collier@Nacho-Linux:~$ pidof firefox
collier@Nacho-Linux:~$
Getting a Process's PID
To get the PID of a process (assuming the process name is known), try the below commands.
  • pidof PROCESS_NAME
  • ps aux | grep PROCESS_NAME
  • kill -p PROCESS_NAME
  • kill --pid PROCESS_NAME

NOTE: Not all systems and kill commands support "kill -p" or "kill --pid".

When combining a PID-finding command with the kill command, a user could type something like
Code:
kill -TERM `pidof geany`
Kill PID 0 and Negative PIDs
If the kill command is used and a PID of zero "0" is specified, then all processes with the same Group ID (GID) of the sender will be affected by the kill signal.

If the specified PID is negative one (-1) and the user is not using Root-privileges, then all of the processes with the same User ID (UID) as the sending user are killed. However, if the sender is Root or using Root-privileges, then all processes except system processes, processes with a Process Group ID (PGID) of 1, and the sending process are killed.

The System V standard specifies that negative PIDs more negative (smaller) than one (i.e. -2, -3, -4, ...) will act like PID -1, but in addition, kill only those processes with a process Group ID equal to the absolute value of the negative PID. This means PID -2 will affect processes with a Process Group ID (PGID) of 2 (since |-2| = 2 or abs(-2) = 2).


source:http://www.linux.org/