Google Plus

Managing your services and processes in Linux

Written by Mel Kham on . Posted in Linux tutorials

As an administrator it is essential that you correctly manage your services and processes which are running on your server, not only to maintain server integrity so that terminalsoftware doesn’t crash, but also to properly manage security.

Ask yourself, if a hacker was able to gain access to your server and run a remote shell in the background, would you be able to indentify it or would you even realize that it has happened to you? Systems administrators should always be aware of what is happening on their servers, it is a part of the job requirement.

What’s the difference between a service and process?

 Let’s start out by discussing first what the difference between a service and a process is. In Linux a service is just another name for a daemon, which is a client / server application that runs in the background. A service is continuously listening for incoming requests and sends a response based on the request given. A process is simply an application or a script which can be running in the foreground or the background.

 To start out you can check what services you currently have running by typing:

 Service –status-all

 Service is a command which allows you start, stop or restart services running in the background. In this tutorial we will use the apache service httpd as an example.

 To start the apache service type:

 Service httpd start

 Services can also be found in the /etc/init.d/ directory and can be controlled in the same manner.

 /etc/init.d/httpd start

 

Indentifying an unknown service

 Apache is a web server which by default runs on port 80 using the service name httpd. Let’s say for the sake of an example we don’t know what httpd is so we want to find out what port it is running on and what data is being sent and received from this service. The first thing we can do to determine what port httpd is running on is to use the netstat command.

 Enter the following command to indentify what ports each service is using.

 Netstat –tulpn

 You will notice a series columns containing information such as the protocol, local address, PID and state. Take note of the local address in the column containing httpd “0.0.0.0:80”, using this we can identify that httpd is running on port 80.

 Next we want to indentify what is being sent and received from port 80 and we know that httpd is using the TCP protocol, so we can use a packet sniffer called tcpdump to view the raw information being sent from port 80.

 Enter the following command in your terminal to sniff the data being sent and received from port 80:

 tcpdump port 80 –w dump.txt

 Next open up Firefox and browse to your default apache web page by typing in http://127.0.0.1 for the local address of the web server.

 If you were able to display the default apache web page, go back to your tcpdump and hit ctrl + c to stop it from running. Now we can take a look at what is being sent and received from this process.

 The first thing you will see when you open up dump.txt is the request to display HTML information from the client.

 GET / / HTTP/1.1

Host: 127.0.0.1

User-Agent: Mozilla/5.0 Firefox/5.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip, deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Connection: keep-alive

Cookie: testing=1

 Below that you will find the servers response.

 HTTP/1.1 200 OK

Date: Wed, 29 Jun 2011 14:46:12 GMT

Server: Apache/2.2.13 (Fedora)

Content-Length: 900

Connection: close

Content-Type: text/html;charset=UTF-8

Then shortly after the response is the HTML for the web page to be displayed.

So we now know exactly what httpd is sending and receiving to be able to indentify if the service is harmless or malicious.

Managing processes

 Linux has two commands which come to mind for managing processes, ps and top. These two commands can be used for displaying process information which can be used to stop unknown processes from running in the background. In this tutorial I will be covering top.

 Top is almost like the Windows equivalent to the task manager, it displays a list of information on each process and frequently updates in order to continuously monitor information about each running process. To run the top application simply type in “top” from your terminal.

 Top will bring up a list of information about each process including how much CPU and memory each process is using and also the PID or process identifier which we will be using to kill a process. Using top you can indentify a service or process which you don’t want to be running in the background such as our example given before of httpd. Identify what PID httpd or apache is using and use the following command to kill that process or service:

 Kill 1234 (1234 in this case being the PID of the running process)

 Be careful not to kill and processes which may be important or critical to the running of Linux, I am not responsible for any damage to your server if you decide to kill the wrong process.

{module user9-footer|none}

For questions please refer to our Q/A forum at : http://ask.unixmen.com

Mel Kham

Founder of Unixmen, Living in Amsterdam. Am working in my free time to help people to understand the Opensource and to explain them in easy way how to make the fist steps to the the light. Working day and night with my Co-founder Zinovsky to keep this website live even with less resources.
  • Sergio Roysen

    I think that your spell checker is changing the case of the first letter of the commands you are referring to.
    The proper way to invoke them is:
    service, not Service
    netstat, not Netstast
    kill, not Kill

    The default format that tcpdump uses when writing the captured traffic to a file with the -w option is pcap, a binary format. You will need a suitable viewer (tcpdump itself, tethereal/wireshark, others) to open it and see its contents.

  • Mark Preston

    I cannot find the "Service" command in Ubuntu Natty.

    And what is this?

    {emailcloak=off}

    I cannot send this comment and leave that line in the E-mail box.

  • http://enteryoursiteURL... Ram

    What happens with IPV6 implementation?

Like us on Facebook

This week Top Posts

Write for us

Recent Comments

Adhraa

|

Greate tutorial :)

pigmej

|

Just one thing:

What about pep8 in your python code ? How can you give ‘tutorials’ on quite popular website, of such a bad quality ?

Amit Rai

|

I just renamed shared.xml and it logged in and created a new shared.xml.

DB Griffin

|

Larry Page is not being completely honest! The manner in which the PRISM program/project works does not need access from company administrators or owners, so called “direct access”; the access to the information is already there. These tech company CEOs take for granted the actual intelligence of most end users of their products. All it takes is a little digging and reading to go from ignorant to informed on these things especially on exactly how the internet works/functions in the U.S.A. I find Larry Page’s remarks just as laughable as Al Gore’s claim to “inventing” the internet/world wide web!

If you, as an end user, are reading this post; I challenge you to research these matters yourself. It really is quite simple with all the “information sites” that exist on the web today ie Wikipedia, & other online encyclopedias that actually list source material, as well as highly respected tech sites and blogs that also list their source material. Be warned: this is only the tip of the iceberg and these tech CEOs know and understand this; they are scrambling in attempt to perform DAMAGE CONTROL to save the company and what little trust thay have left from their products end users/consumers.

Am I a skeptic? I believe someone has to be or needs to be at this point in time! If your not just a little skeptical of the government, tech companies, and the people that are in charge of these agencies and companies; you need to be, even if just a little skeptic. For your own personal protection and security! I know I was a part of this community for over 14 years!

Anders Jackson

|

As I understand it so do VLC use same encoders as ffmpeg. And yes, there are less code that can break when you use command line instead of a graphical UI.

And may I ask what mono has to do with VLC? *facepalm*

 
IDG Tech Network
Copyright © 2008-2013 Unixmen.com .
Maintained by Anblik .