<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>netstat &#8211; 良的世界</title>
	<atom:link href="https://www.lemonary.cn/tag/netstat/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lemonary.cn</link>
	<description></description>
	<lastBuildDate>Fri, 25 Apr 2025 01:16:16 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://www.lemonary.cn/wp-content/uploads/2024/12/profile-150x150.jpg</url>
	<title>netstat &#8211; 良的世界</title>
	<link>https://www.lemonary.cn</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Linux系统中的进程与端口</title>
		<link>https://www.lemonary.cn/linux%e7%b3%bb%e7%bb%9f%e4%b8%ad%e7%9a%84%e8%bf%9b%e7%a8%8b%e4%b8%8e%e7%ab%af%e5%8f%a3/</link>
					<comments>https://www.lemonary.cn/linux%e7%b3%bb%e7%bb%9f%e4%b8%ad%e7%9a%84%e8%bf%9b%e7%a8%8b%e4%b8%8e%e7%ab%af%e5%8f%a3/#respond</comments>
		
		<dc:creator><![CDATA[shine]]></dc:creator>
		<pubDate>Mon, 09 Dec 2024 02:42:36 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[lsof]]></category>
		<category><![CDATA[netstat]]></category>
		<category><![CDATA[ps]]></category>
		<guid isPermaLink="false">https://www.lemonary.cn/?p=899</guid>

					<description><![CDATA[一、概述 二、查看 2.1 由进程查端口 方法一 获取到进程号是41181，查看该进程占用的端口 方法二-直接 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading" id="一、概述">一、概述</h2>



<ol class="wp-block-list">
<li>在&nbsp;Linux 中，每个执行的程序都称为一个进程。每一个进程都分配一个&nbsp;ID&nbsp;号(pid,进程号)。</li>



<li>每个进程都可能以两种方式存在的。前台与后台，所谓前台进程就是用户目前的屏幕上可以进行操作的。后台进程则是实际在操作，但由于屏幕上无法看到的进程，通常使用后台方式执行。</li>



<li>一般系统的服务都是以后台进程的方式存在，而且都会常驻在系统中，直到关机才结束。</li>
</ol>



<h2 class="wp-block-heading" id="二、查看">二、查看</h2>



<h3 class="wp-block-heading" id="2.1-由进程查端口">2.1 由进程查端口</h3>



<p class="wp-block-paragraph"><strong>方法一</strong></p>



<pre class="wp-block-code"><code>&#91;dmdba@centos-dm ~]$ ps -ef|grep dmserver
dmdba    <strong>41181     </strong>1  0 Aug31 ?        00:00:49 /opt/dmdbms/bin/dmserver path=/dmdata/PROD/dm.ini -noconsole
dmdba    42471 41779  0 16:39 pts/0    00:00:00 grep --color=auto dmserver</code></pre>



<p class="wp-block-paragraph">获取到进程号是<strong>41181</strong>，查看该进程占用的端口</p>



<pre class="wp-block-code"><code>&#91;dmdba@centos-dm ~]$ netstat -anop | grep 41181
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp6       0      0 :::<strong>5239                 </strong>:::*                    LISTEN      41181/dmserver       off (0.00/0/0)</code></pre>



<p class="wp-block-paragraph"><strong>方法二-直接查询</strong></p>



<pre class="wp-block-code"><code>&#91;dmdba@centos-dm ~]$ netstat -lnopt | grep dmserver
tcp6       0      0 :::5239                 :::*                    LISTEN      41181/<strong>dmserver</strong>      off (0.00/0/0)</code></pre>



<h3 class="wp-block-heading" id="2.2-由端口查进程">2.2 由端口查进程</h3>



<p class="wp-block-paragraph">某端口被占用，我们想要查看占用该端口的是什么进程</p>



<pre class="wp-block-code"><code>&#91;dmdba@dameng ~]$ lsof -i:5236
COMMAND     PID  USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
<strong>dmserver </strong>650030 dmdba    5u  IPv6 15626699      0t0  TCP *:padl2sim (LISTEN)</code></pre>



<p class="wp-block-paragraph">得到进程名字 <strong>dmserver</strong> 后，查看进程的开启时间等</p>



<pre class="wp-block-code"><code>&#91;dmdba@dameng ~]$ ps -eo pid,lstart,etime,cmd | grep dmserver
 650030 Tue Nov  5 09:32:57 2024  2-00:23:08 /opt/dmdbms/bin/dmserver path=/dmdata/5236/DMDB/dm.ini -noconsole
 655699 Thu Nov  7 09:56:05 2024       00:00 grep --color=auto dmserver</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lemonary.cn/linux%e7%b3%bb%e7%bb%9f%e4%b8%ad%e7%9a%84%e8%bf%9b%e7%a8%8b%e4%b8%8e%e7%ab%af%e5%8f%a3/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
