Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (18.4k points)

The below command opens the socket with this function:

sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)

After sending data the socket gets closed:

close(sockfd);

But this issue is when my program doesn't run well and is blocking. Thereby this socket will not be closed.

How can I check any sockets opened under Linux OS?

1 Answer

0 votes
by (36.8k points)

Use the below command:

/proc/net/tcp -a list of open tcp sockets

/proc/net/udp -a list of open udp sockets

/proc/net/raw -a list all the 'raw' sockets

These are some files, use the cat command to view them. For example:

cat /proc/net/tcp

You can also use the lsof command.

lsof is the command to open list files, which is used under various Unix-like systems to report your list of all open files and these methods that opened them.

Want to be a Linux expert? Come and join this Linux course

Do check out the video below for better understanding of Linux

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jan 26, 2021 in Linux by dev_sk2311 (45k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...