Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8086133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:21:25+00:00 2026-06-05T18:21:25+00:00

I have to write a SNMP module which monitor a certain server application that

  • 0

I have to write a SNMP module which monitor a certain server application that I have written too. The problem is that I have to know if this application is running and I should be able to kill it whenever I can.

I know the port where the application is listening (reading the application configuration file) and I can try to bind this port to a socket in order to know if it is (or isn’t) being used by my application or another which is enough for my module. Here is the code:

int
get_server_status()
{
        struct sockaddr_in local;
        int port,sockfd;

        if (parse_config_file(&port,NULL,CONFIG_FILE_PATH) == -1)
                return -1; //Error

        if ((sockfd = socket ( AF_INET, SOCK_STREAM, 0 )) < 0)
                return -1; //Error

        local.sin_family = AF_INET;
        local.sin_port = htons ( port );
        local.sin_addr.s_addr = inet_addr ("127.0.0.1");

        if (bind(sockfd, (struct sockaddr *) &local, sizeof (local) ) < 0 ){
                if(errno == EADDRINUSE)
                        return 1; //Port being used
                else
                        return -1; //Error
        }else{
                close(sockfd);
                return 0;         //Port not being used

        }
}

The problem comes when I need to kill the application, I don’t know neither its PID nor how to get it. I can get is using netstat -tln <port>but I don’t know how to do it programmatically. Any ideas??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:21:27+00:00Added an answer on June 5, 2026 at 6:21 pm

    Like netstat, you should read /proc/net/tcp.

    Interpreting it:

    1. The second field, titled local_address, is the IP and port. 00000000:0050 would be HTTP (the port number is in hex).
    2. The 4th field, titled st, is the state. A is TCP_LISTEN.
    3. The 10th field, titled inode is the inode number (decimal this time).
    4. For each process, /proc/pid/fd/ contains an entry for each open file descriptor. ls -l for socket descriptors shows that it’s a link to socket:[nnnnnn]. The number nnnnnn should match the inode number from /proc/net/tcp.

    This makes finding the process quite tiresome, but possible.
    Finding the right line in /proc/net/tcp isn’t difficult, and then you can get the inode number.
    Finding the process requires you to scan all processes, looking for one which refers this inode number. I know no better way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an application so i have write an dll which contain a
I have to write a Matlab script that does this: The input is 2
In SQL Server 7.0, I need to find out which users have write access
I have a web application, written in ColdFusion, which periodically starts using 100% of
I have write some code but my program is too slow. The problem is
I have user global.asax and I have write this code in my ASP.NET application
Suppose that for administrative reasons I do not have write access to module xxx.
I'm writing a simple web app in PHP that needs to have write access
I have to write an XML file using java.The contents should be written from
I have to write a program that sniffs network packets (part1-the simple part). And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.