date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,300,135,516,000
I have two linux servers. Let's say they are C and S. C is client of S On my S machine, I type. $ netstat -an | grep ESTABLISHED tcp 0 0 192.168.1.220:3306 C:57010 ESTABLISHED Then I can know C is connecting now. In the C machine, I'd also like to know the process name which is opening the p...
One way is to say lsof -i:57010 -sTCP:ESTABLISHED. This walks the kernel's open file handle table looking for processes with an established TCP connection using that port. (Network sockets are file handles on *ix type systems.) You'd use -sTCP:LISTEN on the server side to filter out only the listener socket instead. B...
How can I know the process name which is opening a tcp port?
1,300,135,516,000
Both shows the number of files we're using. Yet they both shows different results. root@host [~]# lsof /home4 root@host [~]# lsof /home2 root@host [~]# lsof /home4 Then we got fuser -uvm /home4 root 2621 Frce. (root)crond root 2635 Frce. (root)atd ...
The usage of the two are different. For lsof, to show opened files for certain path only, put -- in front of first path specified: lsof -- /home4 lsof -- /home4 /home2 lsof will show all opened file containing the path. For fuser, on the other hand, show process opening the file you specified fuser -uv <filename> T...
What's the difference between lsof and fuser -uvm
1,300,135,516,000
When I try to remount a partition as read-only, I get an error /foo is busy. I can list all files open from /foo with lsof /foo but that does not show me whether files are open read-only or read-write. Is there any way to list only files which are open as read-write ?
To answer this question specifically, you could do: lsof /foo | awk 'NR==1 || $4~/[0-9]+u/' This will show files which are opened read-write under the mount point foo. However, likely you really want to do is list all files which are open for writing. This would include files a which opened write-only as well as thos...
lsof: show files open as read-write
1,300,135,516,000
I'm trying (with minimal success at present) to setup the Dovecot mail server on my Fedora 24 server. I've installed Dovecot and set the conf file up, all fine. But when I run: systemctl restart dovecot After editing the conf file I get this message Job for dovecot.service failed because the control process exited wi...
netstat is your friend when you're trying to troubleshoot a lot of network-related problems. To find a listening port, I would use netstat -tulpn | grep :<port number> For example, to find what pids are listening on port 22, I would run: netstat -tulpn | grep :22 tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3062/s...
Finding the process id by port number
1,300,135,516,000
This is a hypothetical question, not a problem I currently have. How do you detect which process has used a file now or in the past? To find out which process is accessing filename right now, lsof filename or fuser filename will do the work. But what if one wanted to know which processes accessed filename in the last ...
If your system has audit enabled, you can use that subsystem to audit access to specific files. For example, to audit files opening (or trying to open) the /etc/shadow file, you can use the following rule: auditctl -a exit,always -S open -F path=/etc/shadow Later on, you can then use this command to list the audited ...
How to detect which process has used a file now or in the past
1,300,135,516,000
I am trying to get a list of open files per process. I ran the following one-liner from PerlMonks: lsof | perl -lane '$x{"$F[0]:$F[1]"}++; END { print "$x{$_}\t$_" for sort {$x{$a}<=>$x{$b}} keys %x}' It returns the total count of open files, and the process name and pid. The result is sorted in ascending order, and ...
lsof without arguments gives you the information for all the threads of the every process. While lsof -p "$pid" only lists open files for the process. To get the same number, you'd need: lsof -a -K -p "$pid" Also note that lsof doesn't only list files open on file descriptors, it also lists mmapped files (as seen in ...
Discrepancy with lsof command when trying to get the count of open files per process
1,300,135,516,000
Our memcache daemon reports non-zero 'curr_connections'... $ telnet memcache-server 11211 Escape character is '^]'. stats ... STAT curr_connections 12 ... ...and yet, lsof shows no socket connections: $ ssh memcache-server # lsof -P -i -n | grep memcache memcached 1759 memcached 26u IPv4 11638 0t0 TCP *:112...
I think you're correct in your logic that stat curr_connections is the number of connections that are current. curr_connections - Number of open connections to this Memcached server, should be the same value on all servers during normal operation. This is something like the count of mySQL's "SHOW PROCESSLIST" result ...
Memcache 'stats' reports non-zero 'curr_connections' - but lsof shows no socket connections
1,300,135,516,000
Here is an abridged output of lsof -i tcp:XXXXXX: COMMAND PID USER FD TYPE DEVICE python3 9336 root 3u IPv4 3545328 python3 9336 root 5u IPv4 3545374
$ man 8 lsof | grep -A 10 '^\s\{7\}DEVICE' DEVICE contains the device numbers, separated by commas, for a character special, block special, regular, directory or NFS file; or ``memory'' for a memory file system node under Tru64 UNIX; or the address of the private data area of a Sol...
What does the DEVICE field stand for in lsof? [closed]
1,300,135,516,000
I am using this command below and trying to separate the columns I only want to get the PID to use it in my python script. I can easily get this line by line but then how to separate into columns in a non hacky way? I can easily split by space but lets face it that is a terrible idea, any suggestions? root@python-Virt...
I think awk is good for this because it splits fields for you: lsof | awk '$8 == "TCP" { print $2 }' If field 8 is "TCP", then print field 2.
separate lsof output by column
1,300,135,516,000
I'm working on a Linux (Scientific Linux CERN SLC release 6.9 (Carbon)) machine on which I am unable to install programs and on which the lsof or fuser commands are not available. I'm trying to remove an NFS dotfile on this machine but I keep getting the Device or resource busy error so I'd like to find out which proc...
Use /proc/<PID>/fd. Example....we want to figure out which pid has /var/log/audit/audit.log open. fuser tells us it's pid 255. [root@instance-1 ~]# fuser /var/log/audit/audit.log /var/log/audit/audit.log: 255 [root@instance-1 ~]# So using a non fuser solution: [root@instance-1 ~]# find /proc/*/fd -ls|grep /var/log...
Find processes which have a file open without lsof or fuser
1,300,135,516,000
I have Centos 6.7 running java application via a wrapper programme. So first I ran this. lsof -p 15200 | wc -l and I got the results immediately as 200 next I ran this lsof -p 15232 | wc -l I keep taking too long and never generated any results. What other method can I use to get the total open files? I need to know...
You can get the number files opened by a process identified by a PID, for instance 15232, doing: ls -l /proc/15232/fd | wc -l from the Debian lists: I am trying to figure out the meaning of: /proc/$PID/fd/* files. These are links that point to the open files of the process whose pid is $PID. Fd stands for "file...
lsof command taking too long for a particular process id
1,300,135,516,000
I am looking at the output of lsof -i and I am getting confused! For example, the following connection between my java process and the database shows as IPv6: [me ~] % lsof -P -n -i :2315 -a -p xxxx COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME java xxxx me 93u IPv6 2499087197 0t0 TCP 192....
In Linux, IPv6 sockets may be both IPv4 and IPv6 at the same time. An IPv6 socket may also accept packets from an IPv4-mapped IPv6 address. This feature is controlled by the IPV6_V6ONLY socket option, whose default is controlled by the net.ipv6.bindv6only sysctl (/proc/sys/net/ipv6/bindv6only). Its default is 0 (i.e. ...
Why does lsof indicate my IPv4 socket is IPv6?
1,521,959,301,000
I found a Unix socket being used in the output of the lsof command: COMMAND PID TID TASKCMD USER FD TYPE DEVICE SIZE/OFF NODE NAME screen 110970 username 4u unix 0xffff91fe3134c400 0t0 19075659 socket The "DEVICE" column holds what looks like a mem...
To find the file associated with the UNIX socket, you can use the +E flag for lsof to show the endpoint of the socket. From the man pages: +|-E +E specifies that Linux pipe, Linux UNIX socket and Linux pseudoterminal files should be displayed with endpoint information and the files of the endpoints should also be d...
Interacting with Unix Socket found in lsof
1,521,959,301,000
Finding the PID of an established connection is trivial using netstat or lsof. However, I have a process which is creating a connection ever 60 seconds to our database and locking it up by maxing out the failed connection attempt limit. I can increase the failed connection limit to something extremely high on the data...
Consider using SystemTap. It is dynamic instrumenting engine that dynamically patches kernel so you can track any in-kernel event such as opening a socket. It is actively developed by RedHat so it is supported in CentOS. Installing To install SystemTap on CentOS 6: Enable debuginfo repository: sed -i 's/^enabled=0/e...
log PID of each connection attempt
1,521,959,301,000
The lsof manpage says the following about the TYPE column. TYPE is the type of the node associated with the file - e.g., GDIR, GREG, VDIR, VREG, etc. Can someone please explain (or point me to a link which explains) what these mean. I have tried googling on these but all the links take me to the lsof man page ...
Types starting with V are virtual types. That is, there is no corresponding inode on any physical disk but only a vnode in a virtual filesystem (like /proc). It seems those types only belong to BSD-like systems (AIX, Darwin, FreeBSD, HPUX, Sun etc.) and won't occur on a Linux system. As with the non-virtual types, DIR...
What do GDIR, GREG, VDIR, VREG mean in lsof output
1,521,959,301,000
I use wget to download files (most are zip files) automatically for me during the night. However, sometimes in the morning I find that a few files cannot be unzipped. I don't know why this is happening, perhaps it's something wrong with the remote server. I want to write a script to test zip files in my download fo...
You can use fuser, or lsof. fuser foo.zip The output looks like so: $ fuser archlinux-2013.02.01-dual.iso /home/chris/archlinux-2013.02.01-dual.iso: 22506 $ awk -F'\0' '{ print $1 }' /proc/22506/cmdline wget
How to tell if a file is being downloaded by wget?
1,521,959,301,000
I have a Raspberry Pi running Debian Jessie. I have pi-hole installed to block ad-serving domains (https://pi-hole.net). Going through the logs, I noticed a lot of queries from a Chinese domain. lsof -i shows me the following list that I feel is suspected: COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME sshd...
There may or may not be a security breach. It may just be an idiot trying to brute force crack passwords. If they connect, try a password, it fails, they don't try another or close the connection then you can see these connections which will eventually be closed by the sshd. /var/log/auth.log should have some informa...
Suspicious network activity: sshd process showing up with lsof
1,521,959,301,000
I need a list of the opened files, ports and so on by a process. Now whenever I use lsof -p <PID> I can parse the output, in a python script, but the problem is that sometimes I am getting some columns that are empty. Therefore I am getting bad results while parsing the output. I know that I can manually look for the...
lsof has a "post-processable" output format with the -F option (see the OUTPUT FOR OTHER PROGRAMS section in the manual). lsof -nPMp "$pid" -Fn | sed ' \|^n/|!d s/ type=STREAM$//; t end s/ type=DGRAM$//; t end s/ type=SEQPACKET$// : end s|^n||' Will list open files that resolve to a path on the file syste...
Custom lsof output
1,521,959,301,000
When I run lsof I see the output java 1752736 user 9995u sock 0,8 0t0 1432559505 protocol: TCPv6 java 1752736 user *527u sock 0,8 0t0 1444900878 protocol: TCPv6 What does the * in front of the file ...
Newer versions of the man page explain it (addressing this issue). Checking out its roff source code (emphasize mine): The FD column contents constitutes a single field for parsing in post-processing scripts. FD numbers larger than 9999 are abbreviated to a * followed by the last three digits. E.g., 10001 appears as ...
lsof output file descriptor with asterisk not documented
1,521,959,301,000
I know that lsof can list all files which are being opened by running processes. If there is a process, which will open a file and then will be terminated, I don't think I can catch the file that is opened by the process with lsof because the process terminated itself too fast. So I'm looking for such a tool (named X...
You could use strace: strace -e trace=open -o trace.log ./my_process args
Is it possible to list all files that are opened by a process [duplicate]
1,521,959,301,000
I've noticed, if a file is renamed, lsof displays the new name. To test it out, created a python script: #!/bin/python import time f = open('foo.txt', 'w') while True: time.sleep(1) Saw that lsof follows the rename: $ python test_lsof.py & [1] 19698 $ lsof | grep foo | awk '{ print $2,$9 }' 19698 /home/bfernandez...
You are right in assuming that lsof uses the inode from the kernel's name cache. Under Linux platforms, the path name is provided by the Linux /proc file system. The handling of hard links is better explained in the FAQ: 3.3.4 Why doesn't lsof report the "correct" hard linked file path name? When lsof reports...
How does `lsof` keep track of open file descriptors' filenames?
1,521,959,301,000
I was going through the questions of this site. In this particular question, I see the command lsof being used to list the files that are open for a particular user. I ran the below command in my terminal. lsof -a -u root -d txt I am seeing a long output which are completely irrelevant (at least to me). I am findin...
lsof lists all files that are accessed by a program one way or another. The fourth column (FD) describes the way in which the program is accessing the file. Here are some common cases (there are others): A number: the file is opened by the process, and the number is the file descriptor. Letters after the file name in...
lsof - debug the output information
1,521,959,301,000
Given a pid, I can get all the files open for writing something like: lsof -p 28827 | awk '$4 ~ "[wW]"{print $(NF-1), $NF}' One of those ends up being a pipe: 28827 232611 pipe I want to look-up all the files open by that pipe. If I just do: lsof | grep 232611 That gives me a bunch of processes, one of which is a t...
It should be enough to just grep for digits followed by one or more rs: lsof | grep -P '\b\d+r+\b' Or, if you don't have GNU grep: lsof | grep -E '\b[0-9]+r+\b' The \bs mark word boundaries and ensure that only entire fields are matched. Alternatively, if your grep supports it, you can use the -w flag: lsof | grep ...
Get all files open for writing with pid, recursively
1,521,959,301,000
It threw errors about kernel sources missing. So, I looked and sure enough this box doesn't have them. The documentation I have says to install them via sysinstall. That failed both automatically and manually configured server references. I then found elsewhere that sysinstall is no longer supported and that sour...
Ultimately, the following command line appears to have solved the problem. I don't recall the original source (or command line) I had used, so I don't know if the documentation I was using was wrong or it was a problem with the mirror: svn checkout svn://svn.freebsd.org/base/release/9.2.0/ /usr/src
How do I update lsof port on FreeBSD 9.2?
1,521,959,301,000
I'm running qemu's like this: $ sudo qemu -boot d -m 1024 \ -netdev tap,id=tap0 \ -device virtio-net-pci,netdev=tap0,id=vth0 \ -drive file=ubuntu.iso,media=cdrom,cache=none,if=ide \ -monitor pty \ -serial pty \ -parallel none \ -nographic When I check /dev/pts/: $ sudo lsof +d /dev/pts/ Qemu pty's do not show up, al...
You can do it this way using virsh along with some scripting: $ for i in `virsh list | awk '{print $2}' | egrep -v "^$|Name"`; do printf "%-14s:%s\n" $i $(virsh ttyconsole $i | grep -v "^$"); done cobbler :/dev/pts/1 xwiki :/dev/pts/3 fan :/dev/pts/4 mercury :/dev/pts/5 mungr ...
How can I figure out which pty's are from which qemu?
1,521,959,301,000
We've been working to clean up some space in our /opt mount. A large culprit of space consumption was log files for some processes we run (to the tune of 2 to 12 GB each). We've cleaned these up by truncating them. However, this seems to be skewing our output from df -H. /dev/mapper/Sys-opt 76G 72G 0 100%...
Unix uses reference counting to figure out whether a file is in use or if the data can be deleted/reused. An open filehandle counts as a reference - so until it is closed, this space will be occupied. Restarting the process with the open filehandle will close the filehandle, and if it has been removed from the directo...
Should I be concerned with large (deleted) files in lsof? [duplicate]
1,521,959,301,000
I was trying to figure out what ports are in use on my Linux Ubuntu machine. I was reading the article How to check if port is in use on Linux or Unix and saw one of their commands was: sudo lsof -i -P -n | grep LISTEN I am still getting my feet wet with a lot of Linux commands, but I had just recently learned about l...
-i selects Internet files or sockets. It works with an optional address parameter. Without that parameter, it selects all sockets. You can use additional filters with this option to select by IPv4/IPv6, by TCP/UDP and so on. The manpage lists several examples: -i 4 to select IPv4 sockets, -i 6 to select IPv6 sockets....
What does the "i" flag mean in lsof?
1,521,959,301,000
I am trying to find the reason why my long-running app sometimes busts the maximum open file descriptor limit (ulimit -n). I would like to periodically log how many file descriptors the app has open so that I can see when the spike occurred. I know that lsof includes a bunch of items that are excluded from /proc/$PID/...
tl;dr ls -U /proc/PID/fd | wc -l will tell you the number that should be less than ulimit -n. /proc/PID/fd should contain all the file descriptors opened by a process, including but not limited to strange ones like epoll or inotify handles, "opaque" directory handles opened with O_PATH, handles opened with signalfd() ...
lsof versus /proc/$PID/fd versus ulimit -n
1,521,959,301,000
I am trying to repair permissions on my external HD. I cannot empty my trash when it is plugged in, because I get a bunch of "such file is in use". I read online that this might be resolved by repairing permissions on the drive. I am currently unable to unmount the drive because it is in use the second I restart or un...
Too fast diagnosis I read online that this might be resolved by repairing permission on the drive. Unfortunatly, from the description of your problem, this is wrong. What need to be repaired is the filesystem on your external disk SEAGATE. Analysis of lsof The output of your lsof command tells that the command mds (...
Mac drive in use, understanding lsof
1,521,959,301,000
Sometimes I need to kill a process (the reasons why are not important). And I know I can find that process with the following command: lsof -i :8080, being my candidate the last process in the output table. For example, if I run the command, an output like this will appear: COMMAND PID USER FD TYPE DEVICE SIZE/...
Answering your question literally, here's one way to list the last PID displayed by lsof: lsof … | awk 'END {print $2}' Awk is a text processing language which reads input and processes it line by line. In the code, END {…} executes the code in the braces after the whole input is processed, and effectively operates o...
Command for killing specific PID provided by previous command
1,521,959,301,000
This command is doing the rounds for detecting currently running processes using glibc: lsof | grep libc | awk '{print $2}' | sort | uniq I find it intensely annoying, since /libc/ matches not only libc, but on my system: /lib/x86_64-linux-gnu/libcap.so.2.24 /lib/x86_64-linux-gnu/libcgmanager.so.0.0.0 /lib/x86_64-lin...
That's a roundabout and grossly inaccurate method. You know the location of the library file, so you don't need to use heuristics to match it, you can search for the exact path. There's a very simple way to list the processes have a file open: fuser /lib/x86_64-linux-gnu/libc.so.6 However this lists the processes tha...
How do I detect running processes using a library package?
1,521,959,301,000
I just performed a fresh ubuntu install and i am seeing the following in lsof: userA@az1:~$ lsof COMMAND PID TID USER FD TYPE DEVICE SIZE/OFF NODE NAME init 1 root cwd unknown /proc/1/cwd (readlink: Permission denied) init 1 root ...
It appears that you did not run lsof as root, given that you show a prompt with $. Run sudo lsof to execute the lsof command as root. Some information about a process, such as its current directory (pwd), its root directory (root), the location of its executable (exe) and its file descriptors (fd) can only be viewed b...
root permission denied on /proc/1/exe
1,521,959,301,000
What does this mean? How does lsof find such FDs? I.e. compared to normal FDs, which can be found easily like ls -l /proc/$PID/fd/$FD. $ lsof -p $(pgrep pulseaudio) | head -n1 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME $ lsof -p $(pgrep pulseaudio) | grep DEL pulseaudi 259...
lsof usually reports entries from the Linux /proc/<PID>/maps file with mem in the TYPE FD column. However, when lsof can't stat(2) a path in the process maps file and the maps file entry contains (deleted), indicating the file was deleted after it had been opened, lsof reports the file as DEL. https://stackoverflow...
FD column of `lsof` shows DEL in some cases, instead of an FD number
1,521,959,301,000
I'm trying to use lsof in an IF statement to tar a directory ONLY if other programs are NOT using files within the directory. I can get this info at a shell prompt with lsof +d /mydir/ If it doesn't return any output, I know the directory is not in use. How do I format that into a conditional statement so that if (l...
Count the characters in the answer, like this: #!/bin/bash a="$(lsof +d "${folder}")" if [[ "${#a}" -gt 0 ]] then echo "${folder} in use" else tar "${folder}" fi
How to test if processes are using files in directory
1,521,959,301,000
So, I've been able to figure out bits of this myself but am having trouble piecing them together. I have a task I need to automate - I have folders filled with gigabytes of obsolete files, and I want to purge them if they meet two criteria. Files must not have been modified in the past 14 days - for this, I'm using f...
The following should work: for x in `find <dir> -type f -mtime +14`; do lsof "$x" >/dev/null && echo "$x in use" || echo "$x not in use" ; done Instead of the echo "$x not in use" command, you can place your rm "$x" command. How does it work: find files, last modified 14 days or longer ago: find <dir> -type f -mtim...
How to iterate through files and delete those older than x days but NOT in use
1,521,959,301,000
I've got output coming from lsof -F that looks like this: p7646 g7646 R8300 csocat u1000 Labe f3 au l tIPv4 G0x80002;0x0 d640391 o0t0 PTCP n*:51352 TST=LISTEN TQR=0 TQS=0 I am trying to capture the value 51352, which is a bound port I'm interested in knowing. I'm close in that I can get the n*:51352 value with this: ...
Combine the two: awk -F: '/^n\*:/ {print $2}'
How to capture the port number from this `lsof -F` output using awk (or something better)?
1,521,959,301,000
Output of lsof on my RHEL7 shows that one file with file descriptor mem is used by 40 processes. Does it mean that this file is mapped in memory 40 times or what? Could someone please explain what does memory mapped files mean? Does it mean that it 40 times in my memory? # lsof /usr/lib/locale/locale-archive COMMAND ...
Have a look at the difference between virtual and physical memory. Many processes can map the same physical memory. If 10 processes map the same file, then at most one copy will be cached in RAM. If memory is not-shared, then if one process changes it, then this one page (with the change), is duplicated before committ...
Linux memory mapped files
1,521,959,301,000
I was trying to see the progress of a already running rsync and cp task and found this answer that allowed me to see what was currently happening When i went to the man page for lsof and see that -c is what is used to select the process (cp in the example below) to look at and: -a causes list selection option...
-d3-999 just excludes the standard file descriptors (0,1,2) from the listing. The -d is used to specify a list or range of fds: -d s specifies a list of file descriptors (FDs) to exclude from or include in the output listing. The file descriptors are spec- ified in the comma-separated set...
What does lsof -ad3-999 -c rsync do?
1,521,959,301,000
In the lsof man page, there is the following sentence: An open file may be a regular file, a directory, a block special file, a character special file, an executing text reference, a library, a stream or a network file (Internet socket, NFS file or UNIX domain socket.) What is an executing text refere...
The portions of an executable file that contain the machine instructions are called the text sections, and taken together they're called the text segment. On modern Unix and Unix-like systems, the file containing the text segment is kept open while the process is running so that pages full of machine instructions can ...
What is an 'executing text reference'?
1,521,959,301,000
I often have trouble unnounting filesystems because compton is keeping a subdirectory open. Here is one line from lsof I have right now: compton 30043 valmi cwd DIR 254,0 32768 7485 /media/truecrypt1/videos I cannot for the life of me figure what it is doing with this directo...
The fourth column of lsof's output tells you that this directory is the current working directory (cwd) of the process. Most probably compton was started in this directory. Most probably you might kill the process and restart it in another directory (e.g. /). You might try forcing it to leave the directory with this...
Forcing compton to free directory
1,521,959,301,000
I am reading in man lsof that +L enables the listing of file link counts. A specification of the form "+L1" will select open files that have been unlinked. I don't understand why deleted files should have count 1. Should not the count for deleted files be 0 ?
Well, yes. The manpage on my Debian system says “When +L is followed by a number, only files having a link count less than that number will be listed.”
link count of deleted files
1,521,959,301,000
I want to remove my external HDD as safely as possible. I want to use umount --lazy: Lazy unmount. Detach the filesystem from the file hierarchy now, and clean up all references to this filesystem as soon as it is not busy anymore. (Requires kernel 2.4.11 or later.) Then after a short delay I...
You could try to remount the volume read-only. This works only if nothing on that volume is opened for writing. You will probably not get rid of the race condition that a file could be opened read-only or that a process could have its current working directory on that volume but if you detach the hardware then you can...
List processes accessing device after `umount --lazy`
1,521,959,301,000
I tried with lsof -F c somefile But I get p1 cinit p231 cmountall p314 cupstart-udev-br p317 cudevd Instead of init mountall ... Any way to get just the command?
Man page says procces ID is always selected. depending on your need, you may use awk to filter out process lsof -F c somefile | awk '/^c/ { print substr($0,2)}'
List only commands with lsof
1,521,959,301,000
I'm really sorry if this question was asked before. I really need help with this as it involves very important data and I've been unable to do it for the past 2 hours. Essentially I accidentally removed the wrong folder due to a typo when running rm -r. From what I know the files are still there, but the links are rem...
You could try scripting it yourself: PID=..your process.. export RESTORE_TO_DIR=some_place find "/proc/$PID/fd" -lname '* (deleted)' -printf '%p %l\0' | xargs -0 sh -c ' for l; do f=${l%% *}; t="$RESTORE_TO_DIR${l#* }" echo mkdir -p "${t%/*}" && echo cp -vb "$f" "${t% (deleted)}" done ' sh Remove th...
Recover deleted folder that's still loaded by an active process
1,396,980,259,000
I recently discovered that a buggy program called pcmanfm was writing 200 MB per second to its run.log file, so I had to find ways to combat that. I discovered what file it was that it was writing to in a laborious manner: du -h for various directories trying to find the offending file. I'm now faced with another simi...
I am finding that iotop is quite effective, however it updates its display too rapidly to allow for cut-and-paste of anything like PIDs and program paths. UPDATE: This requires use of the -d option to specify an update delay. UPDATE 2: On Raspbian, sysdig is not available and fatrace is broken.
How to use lsof to find high activity file writing?
1,396,980,259,000
I've got a server with 2 network interfaces. Due to a restrictive NAT firewall, it establishes an SSH tunnel to a server on the internet: ssh -fNTMS "/tmp/tunnel.socket" host; ssh -S "/tmp/tunnel.socket" -O forward -R "0:localhost:22" placeholder Normally it connects via a wired 1GB ethernet connection (eth0); but i...
I'm being stupid... the tunnel uses the default interface with the lowest metric, it's not tired to a single interface. As soon as eth0 comes back up, the data is sent via eth0. This causes the connection to effectively fail, where I need to use ServerAliveInterval/ServerAliveCountMax to notice and close the connectio...
Check which network interface an SSH tunnel is using
1,396,980,259,000
when we run lsof on port 6060 as the following # lsof -i TCP:6060 | more COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME app_lot 3495 root 12u IPv6 9238779 1t0 TCP *:krb0934 (LISTEN) app_lot 3495 root 13u IPv6 9208460 1t0 TCP linux_server45:krb0934->43.55.3.22:5992 (CLOSE_WAIT) app_l...
There is no way to close a socket in the CLOSE_WAIT state (or any other state) externally. If a misbehaving program is accumulating CLOSE_WAIT connections, the only way to free those connections is to kill it. This is a bug in the application, the best solution is to get it fixed. (I’m not saying that’s feasible or re...
Is it possible to force ending of (close wait) connections?
1,396,980,259,000
I known that I can give a specific name to the TUN interface using --dev option, but I didn't and I have now on a router machine something like a hundred client configs. with less clients I was able to dig the log to search for the name of the interface and link it to a named config file, but now there is too much act...
So I came with a solution inspired by A.B comment. $ ps ax | \ awk '/[o]penvpn/{print $7" "$1;system("grep iff /proc/"$1"/fdinfo/*")}'` which give me both running config and it's linked TUN interface.
How to link a tunX interface to a specific OpenVPN instance?
1,396,980,259,000
I'm trying to change the output of lsof -i4TCP:PORT to include a custom name. This will help me identify the server process as started by my daemon. Below is a picture with arrow pointing to what I'd like to control. I've created a custom gem, executed the process there, and it still says Ruby. Rather than go down the...
Thanks to @Stéphane for the great answer. But in my case the best solution was to bundle my scripts as a Mac OSX app. You can control your process name in your project's Info.plist.
How can I change the command title when running a server?
1,396,980,259,000
we have kafka service ( as systemctl service ) and we configured in that service number of open files example: [Service] LimitMEMLOCK=infinity LimitNOFILE=1500000 Type=forking User=root Group=kafka now when service is up , we want to understand the consuming of number of files by kafka services from googled , I under...
The LimitNOFILE directive in systemd (see man systemd.exec) corresponds to the RLIMIT_NOFILE resource limit as set with setrlimit() (see man setrlimit). Can be set in some shells with ulimit -n or limit descriptors. This specifies a value one greater than the maximum file descriptor number that can be opened by thi...
how to find the number of open files per process
1,396,980,259,000
On Solaris, when I type the command lsof -l I encountered this error: lsof: can't read namelist from /dev/ksyms Anyone knows what this error means and how I can get open the list of open FD's using lsof in Solaris?
From the lsof FAQ: 17.12.7 Why does lsof on my Solaris 7, 8 or 9 system say, "can't read namelist from /dev/ksyms?" You're probably trying to use an lsof executable built for an earlier Solaris release on a 64 bit Solaris 7, 8 or 9 kernel. The output from lsof -v will tell you the build envir...
"lsof: can't read namelist from /dev/ksyms" on Solaris
1,396,980,259,000
I just wonder if somewhere we have some command that gives the following we have server - RHEL 7.2 redhat version usually before umount on mount point folder , we need to kill the PIDS that related mount point folder example lets say we want to perform umount /golden/mnt1 So we need to kill all PID that related to...
fuser -k -m /golden/mnt1 See man fuser
find & kill the processes on mount point folder before umont
1,396,980,259,000
I want to know if kill the delete process , can help to clean the memory cache sometimes we get from lsof many deleted files so does killing them can give more available memory ? example: lsof | grep delete lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/42/gvfs Output information may be incom...
Often processes expressly create and open files and delete them directly so that the file can be used more securely, and to ensure that the file is removed when the process ends. In short, this is a feature; especially with the files you show in your question. Killing these processes will disturb the workings of your ...
kill deleted files and clean the memory cache
1,396,980,259,000
I don't know quite how to ask this question and I'm not even sure this is the place to ask it. It seems rather complex and I don't have a full understanding of what is going on. Frankly, that's why I'm posting - to get some help wrapping my head around this. My end goal is to learn, not to solve my overall problem....
When I run a perl script from within a perl script via backticks, (the inner script is the one falsely thinking there is input on STDIN) The inner script RIGHTLY thinks there's input on STDIN, it's just that another file open got file descriptor 0 (which, to perl, is always gievn the file handle STDIN). As you know,...
Edge case - detecting input on STDIN in perl
1,396,980,259,000
I have SSH'd into a remote machine. I would like to get the current working directory (and ideally execute commands like ls) on that remote machine, but from outside this process. Here are my processes $ ps 49100 ttys001 0:00.21 -zsh 52134 ttys002 0:00.21 -zsh 52171 ttys002 0:00.05 ssh [email protected] Term...
If this just isn't possible, would there be something I could do before SSHing into the remote machine that would allow me to do this? You could start the ssh client in the "connection sharing mode": ssh -M -S ~/.ssh/%r@%h:%p user@localhost user@localhost's password: ... user@localhost$ echo $$ 5555 user@localhost$ ...
Get working directory inside SSH client process from outside process
1,396,980,259,000
I need to write lsof output for several network ports into bash variable. Simple $(lsof -i :5555) doesn't work - lsof waits for quit command (Ctrl-C) every time I call it. I can't figure out how to solve my task.
A long running lsof process usually means that DNS resolution is timing out or not working correctly which is delaying the output of it. You can disable DNS resolution by adding the -n option. Of course you might want to check out why DNS resolution is taking too long on your server as well.
run lsof in non-interactive mode
1,396,980,259,000
I am looking for a way to track which files are used by program installer(InstallAnywhere). I cannot use lsof because as far as I know it works on active processes and I want a tool which will work something like that: Time: -------------------------------------------------------- Tool start here: |----------------...
You can also consider invoking your command under strace: strace -f -e trace=file -o /path/to/logfile your_command logfile would contain every file-related operation performed by your_command or its child processes.
Tracking which files are used by program
1,396,980,259,000
pfiles in Solaris suspends files for a short period while examining them, however, lsof does not. How does lsof work that allows it to retrieve information while not suspending files?
Well, lsof read the kernel volatile memory, while pfiles directly read directly from the application interface, thus causing it to suspend for a short period of time. For that reason, lsof does not truly provide an accurate system picture of the system, but it's better then the option of freezing the process while ins...
lsof compares to pfiles, difference?
1,396,980,259,000
Per the EXAMPLES section in the lsof(8) man page on manpages.ubuntu.com, I should be able to run a command/take action if a process has a file open: To take action only if a process has /u/abe/foo open, use: lsof /u/abe/foo echo "still in use" When I try this syntax (in repeat mode), it doesn't work: $ lsof -r /u/...
Even though the manpage lists it, that is not a valid lsof invocation. lsof will consider echo and still in use as names: lsof /u/abe/foo echo "still in use" To have a result from lsof and act on it you could use the exit code. In bash: lsof filename && echo "still in use" or: lsof filename || echo "not in use" If ...
Have lsof take action if a process has a file open — and, ideally, do so repeatedly
1,396,980,259,000
I'm hitting an issue where I need to get the unresolved symlink of a shell process. For example given a symlink ~/link -> ~/actual, if bash is launched with a $PWD of ~/link, I need to fetch that from outside the bash process. Getting the resolved cwd is possible using lsof or /proc as called out in https://unix.stack...
The logical value of the current working directory (logical cwd, what you call “unresolved pwd”) is an internal concept of the shell, not a concept of the kernel. The kernel only remembers the fully resolved path (physical cwd). So you won't get the information you want through generic system interfaces. You have to g...
Get the unresolved pwd of a shell from another process
1,396,980,259,000
Under the folder /home/testing/scripts on a Linux machine, we have 234 different scripts that do sanity and testing as /home/testing/scripts/test.network.py /home/testing/scripts/test.hw.py /home/testing/scripts/test.load.sh . . . in some cases we want to kill all running scripts so in order to find the running scrip...
You could tidy up the command a little, but it seems to me that it's reasonably accurate already. I'd match the filename more tightly to reduce potential mismatches, and I'd ensure that each candidate PID was actually numeric, lsof | awk -v p='^/home/testing/scripts/' '$9~p && $2+0 {print $2}' | sort -u | xargs echo k...
what is the right way to know all script PIDS that runs under folder
1,396,980,259,000
On an Ubuntu VM iotop shows me that some "apache2 -k start" processes are producing a total disk read load of constantly between 4 M/s and 7 M/s even while no requests are being logged. lsof shows me about 5000 regular files being used by www-data. How can I determine what is causing so much disk IO while there should...
Indications of high I/O will likely require a tracing tool to dig into the details of what that I/O is; strace is a common way to do this: strace -e trace=file -ff -o output -y -p $some_httpd_pid_here -e trace=file traces file related operations (there's other handy specifiers, see the fine manual) though will not s...
Apache: High disk read load, no requests
1,396,980,259,000
I need to check the number of file descriptors which are open by a Java process. The output of lsof is almost 40000 lines long. Here's just the beginning: COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME java 12003 jboss cwd DIR 253,7 4096 1835012 /obcdn/Jb...
mem aren't FDs, they're from mmap(). So I would grep -v " mem " to be sure. cwd, rtd, and txt are not FDs either, but there should be exactly one of each, so they won't have a very significant effect on your numbers.
Count the number of file descriptors opened by a process with lsof
1,396,980,259,000
As a follow up to an answer about unsynced files i was wondering if lsof counts delayed writes as open files? If an application has closed a file, but the file is not yet physically on the device, but still in the kernel buffer, pending a delayed write to the actual device, does lsof list such a file as open or is it ...
It's considered closed, and will not be shown. If it considered it open, what file descriptor would you expect it to report? Closing a file removes the file descriptor. I don't think there's any command that will tell if there are buffered writes to a file. But as mentioned in the other question, the eject command on...
Do `lsof` listings include unsynced/delayed writes?
1,396,980,259,000
I use Linux Mint 13, and sometimes (rarely) I find myself not being able to list my home directory contents. When I try to do so: $ cd $ ls then, ls just waits indefinitely. The same with any other application when it tries to read directory contents: I have to kill that application eventually. I have used this linux...
Processes attempting to access a filesystem block indefinitely if the filesystem driver never responds. For a filesystem that is stored on a storage device, the main cause for not responding is that the underlying hardware is not responding or is faulty. This usually produces copious messages in the kernel logs (visi...
Failed to list directory contents: process waits infinitely
1,396,980,259,000
root@host [~]# fsck /home2 fsck from util-linux-ng 2.17.2 e2fsck 1.41.12 (17-May-2010) /dev/sdb1: clean, 6018617/91578368 files, 54524459/366284000 blocks root@host [~]# fsck /home4 fsck from util-linux-ng 2.17.2 e2fsck 1.41.12 (17-May-2010) /dev/sdd1: clean, 8094369/91578368 files, 75999625/366284000 blocks fsck ret...
It is possible your VolGroup-lv_root is created on that drive. Check output of following command pvs It display physical volumes information about LV. More info about LVM (1), (2), (3)
iostat report huge writes to drives that's not even mounted
1,396,980,259,000
Possible Duplicate: Access history of a file I know if a file is "being accessed" I can use lsof to see who (which process) is accessing it, but lsof is slow and heavy and I don't think I would be able to run it fast enough to see if a file is accessed or not. So it there a way to watch a file, and see if it eve...
Assuming you're running Linux: You can use the audit subsystem to monitor access to a particular file. You can use the inotify subsystem to watch for activities on files. There is a nice API for inotify, which makes it more useful for somethings than the audit subsystem, but inotify does not provide you with any info...
How can I monitor if anybody (any process) access is certain file [duplicate]
1,396,980,259,000
I run a python code inside docker container performing the following calls import socket as s,subprocess as sp;s1=s.socket(s.AF_INET,s.SOCK_STREAM); s1.setsockopt(s.SOL_SOCKET,s.SO_REUSEADDR, 1);s1.bind(("0.0.0.0",9001));s1.listen(1);c,a=s1.accept(); I'm trying to get info using ss and see the open sockets, but can't...
You have to switch to the correct network namespace first, because socket state is per namespace (namely per network namespace). For example by using nsenter. sudo has to be moved first, because nsenter also requires privileges. In one line (and using ss's own filtering features) this becomes: sudo nsenter -t $(docker...
ss doesn't display socket info related to the process opening SOL_SOCKET
1,396,980,259,000
Have a file File.txt and if any process is trying to copy the file from /source/ to /destination/ Is there a way to identify if the file File.txt (or any other file ) available in /destination/ is completely copied, or the process is still going on. I tried lsof but its not working **Error** : lsof: WARNING: can't s...
Try to use rsync with --progress option next time. Here is a little snippet that will help you to get the progress status every second until it reaches 100% percent ; Just replace your source and destination file paths. n="$(du -sh <path_to_your_source_file> | awk '{print $1}' | sed 's/[^0-9.]*//g')" while true; do so...
is there any way to identify if a file is still being copied from one directory to other
1,396,980,259,000
I am running Jenkins with lots of jobs which require lots of open files so I have increased file-max limit to 3 million. It still hits 3 million sometimes so I am wondering how far I can go. Can I set /proc/sys/fs/file-max to 10 million? How do I know what the hard limit of file-max is? I am running CentOS 7.7 (3.10....
The kernel itself doesn’t impose any limitation on the value of file-max, beyond that imposed by its type (unsigned long, so 4,294,967,295 on typical 32-bit systems, and 18,446,744,073,709,551,615 on typical 64-bit systems). However each open file consumes around one kilobyte of memory, so you’ll be limited by the amo...
How to find max limit of /proc/sys/fs/file-max
1,396,980,259,000
I have a computer periodically syncing folders of content with another computer using Resilio Sync. The receiving computer has a sorting process on an hourly cron, which analyses the folders and their contents before moving & cataloging them in a seperate filesystem. My issue is the hourly cron will run and process fo...
I suspect there are many ways to do this. The first that came to me to to include a checksum. On the sending server you can run: tar -cf - FILES | md5sum > my_sum.md5 Where we use tar to create (c) a file (f) onto stdin (-) from FILES which can be a glob, directory, or space delineated list of files which then gets p...
How do I confirm a file sync has completed before executing a command?
1,524,503,234,000
I set my TCP server to localhost 127.0.0.1, but instead of seeing 127.0.0.1 in the host portion of the lsof output, I see an asterisk. After running lsof -i... my_process 66666 root 5u IPv4 0xffff...c0 0t0 TCP *:5001 (LISTEN) What does this asterisk mean? Is my socket bound to localhost, does it not have an address ...
That means that limiting your server to localhost was not successful (maybe you have to restart is?) because it is listening on all interfaces, accepting all destination IP addresses.
What does the asterisk (*) mean in lsof output?
1,524,503,234,000
Looking for a way to pass the second column of output to geoiplookup, ideally on the same line, but not necessarily. This is the best I can muster. It's usable, but the geoiplookup results are unfortunately below the list of connections. I wanted more integrated results. If anyone can suggest improvements, they would ...
In terms of improvements, it'd depend on what data from lsof -Pi you're interested in. Here's a "one liner" (not so much..) that prints command, PID, user, node, IP, port & geoip: echo -e "COMMAND\tPID\tUSER\tNODE\tIP\tPORT\tGEO"; IFS=$'\n'; for line in $(lsof -Pi | grep ESTABLISHED | grep -E '*(([0-9]{1,3})\.){3}([0...
Trying to pass some output of lsof -Pi to geoiplookup
1,524,503,234,000
When I use ss (socket statistics) to show the usages of port 5432 I get: $ sudo ss -ln | grep -E 'State|5432' Netid State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess u_str LISTEN 0 244 /var/run/postgresql/.s.PGSQL.5432 54481 * 0 tcp LISTEN 0 244 ...
It turned out it was after all a problem on my machine. I had another instance of WSL running side to side that I forgot of and that one had a Postgres server running and listening to that port. I wrongly assumed they were running in isolation from each other while instead they are not. Uninstalling Postgres from that...
Why ss show a port is in use but lsof doesn't?
1,524,503,234,000
I am attempting to find the best way to determine when the second file (of a matching criteria) is created. The context is an audit log rotation. Given a directory where audit logs are created every hour, I need to execute a parsing awk script upon the audit log that has been closed off. What I mean by that, is that ...
For closure, this is the start of the script I am going to use. It needs more work to make it robust and do logging but you should get the general idea. #!/bin/sh # This script should be executed from a crontab that executes every 5 or 10 minutes # the find below looks for all log files that do NOT have the sticky b...
How to determine the newly closed file within a continuous audit log rotation?
1,524,503,234,000
when we run lsof to capture deleted files , we see the following: ( example ) lsof +L1 java 193699 yarn 1760r REG 8,16 719 0 93696130 /grid/sdb/hadoop/hdfs/data/current/PLP-428352611-43.21.3.46-1502127526112/current/path/nbt/dir37/blk_1186014689_112276769.meta (deleted) what is the reason that P...
Too long to put in a comment, so adding as an answer: That's a Java application keeping those files open, so yes, this scenario can be avoided by using a proper programming style and using the ObjectOutputStream object: //create a Serializable List List lNucleotide = Arrays.asList( "adenine", "cytosine", "guanine", ...
is it possible to avoid open files? [closed]
1,524,503,234,000
My server is compromised, and I try to get the open files of the malicious user, it says that the user does not have a UID , so it cannot find anything. I see there are processes which are running by that user but I cannot get the files opened by it.
it says that the user does not have a UID I can certainly agree with that. A user as defined by "malicious user running things on a server" does not have an UID, but that is because that user is a person who may (perhaps) run things as different UIDs on your machine (from now on I'll stick to the term "attacker"). ...
why the username does not have a UID?
1,524,503,234,000
If I try to umount a mounted disk. It says I can't because it is used by another process, which is strange because I have nothing accessing it that I can find. So I tried using lsof to find what is using it. And the result is as below I can't because of bash. Well that's the most generic info ever. How can I find wha...
The problem is you are current "in" the mounted drive. It says that in your screenshot here: [root@localhost vldsk_damo] If you issue pwd (at a guess) it will say: /mnt/vldsk_damo Best fix, type cd (to send you to your $HOME) or cd /, then try umount ...
A mounted device is busy because bash is using the volume
1,524,503,234,000
Using lsof command I would like to print out TCP connections with ESTABLISHED state but ignoring the ones with localhost. I tried: lsof -itcp@^127.0.0.1 -stcp:established lsof -itcp@(^127.0.0.1) -stcp:established lsof -itcp -i ^@127.0.0.1 -stcp:established and others similar, but always getting sintax error response....
It doesn't look like you can negate network addresses in lsof. If on Linux, you could use lsfd from util-linux instead: lsfd -Q '(type =~ "^TCP") and (name =~ "state=established") and (name !~ "addr=(\[::1\]|127)")' Or as mentioned by @A.B ss from iproute2: ss -tp state established not dst 127.0/8 n...
how can I list, with lsof command, TCP Established connections ignoring localhost?
1,524,503,234,000
Using the -F option for lsof, I can specify which fields are printed: lsof -w -F pcfn However, the output is split on multiple lines, ie one line per field: p23022 csleep fcwd n/home/testuser frtd n/ ftxt n/usr/bin/sleep fmem n/usr/lib/locale/locale-archive fmem n/usr/lib/x86_64-linux-gnu/libc-2.28.so fmem n/usr/lib/...
The lsof -F output is meant to be post-processable. AFAICT, lsof renders backslashes and control characters including TAB and newline¹ at least when they're found in one of the fields with some \x notation (\\, \t, \n for backslash, TAB and newline respectively here)², so it should be possible to format that output u...
lsof: print custom fields on one line
1,524,503,234,000
I have the following output from lsof -i:portnumber [ztao@MongoDB ~]$ lsof -i:6379 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME redis-ser 5341 ztao 4u IPv6 23457 0t0 TCP *:6379 (LISTEN) redis-ser 5341 ztao 5u IPv4 23459 0t0 TCP *:6379 (LISTEN) redis-ser 5341 ztao 6u IPv4 23533 ...
localhost:6379->localhost:6633 (ESTABLISHED) means that there’s an established connection between localhost’s ports 6379 and 6633. (“Established” is a state in the TCP/IP state machine; other protocols have similar states.) The arrow doesn’t represent a direction in terms of communications; it reflects the ports’ owne...
How to interpret the port mapping strings under name column of lsof results?
1,524,503,234,000
I am working with CentOS 7 OS hosting a set of docker containers. By using a web browser I can reach a service on port 80 and I get back a response. A bit of local knowledge helps me understand that the response comes from one of the docker containers. However, I have a big problem: I can't seem to find a way for the ...
Are you certain the docker host is listening on port 80? It might be redirected from port 80 to whatever port it is listening on using the built-in firewall. If you are running IPTABLES, you could check this by using: iptables -L -t nat You would then see a chain named DOCKER which will tell you what redirects are in...
How can I get CentOS to correctly list open ports?
1,524,503,234,000
A strange situation. I started telnet 0 8081 and lsof -i (run under root) doesn't list this connection, but netstat -n does. Why can this be?
I just simulated your scenario and was able to get 8081 in both netstat and lsof. lsof -i displays 8081 as tproxy and so your grep might not be finding it. Try this with -P which shows the numerical ports: lsof -i -P | grep 8081
Why can `lsof -i` not show an open connection which `netstat -n` lists?
1,524,503,234,000
I have several problems: some process is attempting to send data and the firewall is rejecting it at the rate it is sending it out firewall logs flood the system (may need to rate-limit the logging) lsof -i :port does not list the process, but there has to be something causing the packets to keep being sent. netstat...
I couldn't resolve what was trying to connect, but what killed whatever process was trying to connect was simply ifconfig interface_name down.
what process is listening on a given port
1,524,503,234,000
when I use lsof as regular user, I get following warnings: lsof: WARNING: can't stat() tmpfs file system /home/testuser/.cache testuser is another user on my systems, and my own user has no access to the tmpfs filesystem mounted at /home/testuser/.cache. I suspect, lsof found in /etc/fstab (or in /proc/mounts) that t...
You can disable warnings with -w: lsof -w
lsof: WARNING: can't stat() tmpfs file system
1,524,503,234,000
Is there any way to combine the -i and -p options of lsof in a logical conjunction? It seems to me that the default behavior is to show files which satisfy one or the other condition, which I think is a bit odd.
Use the -a option as shown in one of the examples in the lsof man page: To list all open IPv4 network files in use by the process whose PID is 1234, use: lsof -i 4 -a -p 1234 The “Options” section explains: Normally list options that are specifically stated are ORed - i.e., specifying the -i option without an...
Combine multiple lsof options
1,524,503,234,000
We can list only files opened by a specific PID as lsof -p 1000 lsof -p 1000 | wc -l How can we list/count the files opened by a specific program/COMMAND (e.g., java)? And so much better, if we can group the number of open files for each program. I want to inspect which programs have high numbers of opened files. I ...
I don't think there is an argument for such a thing implemented on lsof and I don't know what flags are available on your lsof binary. I think you could achieve what you want with something like this, maybe replacing the head with a 'grep java': lsof | awk '{print $1}' | sort | uniq -c | sort -rn | head lsof: Basic...
How can we count/list all files opened by a specific program/COMMAND? [duplicate]
1,524,503,234,000
I need to test whether any process is listening on a specific socket; fuser does not exist on the target system but lsof does. I run this command: lsof -tU /path/to/socket It lists the PID of the listener, which is great but lsof exits with a status of 1. I change the command to see what's wrong: lsof -tUV /path/to/s...
If you're on a system with a recent version of ss (like that from iproute2-ss190107 on Debian 10), you can use ss instead of lsof: sock=/path/to/socket ino=$(stat -c 'ino:%i' "$sock") && ss -elx | grep -w "$ino" sock=/path/to/socket if ino=$(stat -c 'ino:%i' "$sock") && ss -elx | grep -qw "$ino" then # yeah, someb...
How do I get lsof to stop complaining when testing for a socket?
1,524,503,234,000
In linux we can run ss -x or lsof -U +E and we can see what type unix socket has. But in macOS there is no ss or we can run lsof -U which only shows TYPE - unix, but I would like to know with some utility what exactly so_type a unix socket has.
MacOS appears to support the 'netstat' command. Netstat has long been deprecated for linux due to the interface it used. 'ss' is a syntactically similar command for linux.
How can I find out what so_type an existing unix socket has in macOS?
1,524,503,234,000
from lsof we can see the following output lsof /var | grep delete rsyslogd 9664 root 4w REG 253,2 25589554694 67267903 /var/log/messages-20210513 (deleted) rsyslogd 9664 root 7w REG 253,2 9865832185 67294059 /var/log/secure-20210619 (deleted) libvirtd 9666 root 21r REG 253,2 ...
You may define a maximum file size limit for a process via prlimit prlimit --fsize=1G:2G -p 12345 sets soft and hard file size limits for the process with PID 12345 to 1 and 2 gigabytes (or gibi ... not entirely sure), respectively. This may be done even after the process started. Be aware that this will kill the pro...
how to avoid delete files that comes from gdm-session & cause of increasing used /var
1,524,503,234,000
Is there a way to list all the files being opened on the system? Either display all the currently opened files (with their full path, probably some lsof option), or, more interesting in my case, just list the pathnames as they are being opened (in the manner of tail -f), which I don't think lsof is able to do.
The program inotifywait is intended for performant file monitoring such as what you are looking for. Here is a proof of concept: $ inotifywait -qrm -e open -e access --format "%e %f" tmp/ OPEN hello OPEN,ISDIR ACCESS,ISDIR OPEN hello The output comes from running touch tmp/hello, followed by less tmp/h<TAB> (which t...
Is there an open filename monitor?
1,524,503,234,000
On one session I append some text to a file as below : while true;do echo some_text >> file1 ; done On another session from same dir I run : lsof file1 which returns no output. Any idea why ? Shouldn't lsof report the process writing to the file ? I'm on RHEL 7.2
It just "bad luck" (or if you prefer, a very narrow time window). You can slow the process with pv to throttle the writes to lengthen the time during which the file is open: echo "0000000000000000000000000000000000000000000000000000000000" | pv -L 2 >> opened.dat and in another terminal: lsof opened.dat COMMAND PI...
While appending text to a file, lsof doesn't show the file as being open / accessed
1,524,503,234,000
This is a problem I often encounter, this time with the output of lsof, but I am searching for a general solution for such problems: selecting a column. Here I try to get the TYPE column of the output of lsof COMMAND PID TID USER FD TYPE DEVICE SIZE/OFF NODE NAME lsof...
You can use the -F option to get output more suitable for parsing e.g. lsof -F t | awk '/^t/ {print substr($0,2)}' See the OUTPUT FOR OTHER PROGRAMS section of man lsof More generally, unless your fields are delimited unambiguously you may need to resort to searching for the character position in the header line e.g...
Get a certain column of an output with content aligned right and some columns not always filled
1,524,503,234,000
I am exploring oracle processes and it's lsof output. I am wondering what is /proc/<pid>/cmdline. 145 same cmdline openfiles displayed for each process of oracle. So what exactly is this? Eg: #lsof -u oracle | grep cmdline oracle 2664 oracle 17r REG 0,3 0 9492 /proc/1/cmdline oracle ...
From the manpages for proc(5): /proc/[pid]/cmdline This read-only file holds the complete command line for the process, unless the process is a zombie. In the latter case, there is nothing in this file: that is, a read on this file will return 0 characters. The command-line arguments appear in this file as a set of...
Why all oracle processes are reading /proc/<pid>/cmdline of multiple system processes?
1,524,503,234,000
I want maximize the number of folders encrypted with ecryptfs and decrypted at login with the module pam_ecryptfs.so. Which folders cannot possibly be encrypted before login in? I guess a lsof ran by pam_exec.so should give me the answer. Do you have a better strategy? Example of whitelisted folders: /boot, /etc/pa...
Ecryptfs is designed to encrypt a user's home directory. Although it can be used otherwise, it wasn't designed for that and won't be easy to set up. Ecryptfs normally gets mounted at login time, so it can only encrypt the user's data. A user's data is normally under the user's home directory, that's what the home dire...
What are the folder that I cannot set as encrypted folders decrypted at login? [closed]
1,524,503,234,000
I found this command line is not working ssh i01n10 "/usr/sbin/lsof -p $(pgrep -nf a.out)" it shows the error lsof: no process ID specified However ssh i01n10 "$(pgrep -nf a.out)" correctly gives the PID Why lsof is not seeing the PID?
The lsof command can't see your PID because of shell expansion. That means $(pgrep -nf a.out) will be executed on your local server, not remote. To avoid this expansion, use single quote instead of double quote. Simple example: $ foo=local $ ssh debian8 "foo=remote; echo $foo" local $ ssh debian8 'foo=remote; echo $...
Why "lsof" is not working when it used in ssh? [duplicate]
1,524,503,234,000
pidof returns a space separated list of pids. lsof -p requires a comma serparated one. This can be solved with sed via: lsof -p `pidof postgres| sed -r 's/ /,/g'` However, the extra pipe seems a bit much for a simple operation. Is there a simpler way?
A good alternative is psgrep -d , lsof -p $(pgrep -d , postgres) -d Specifies the delimeter.
More succinct alternative to "lsof -p $(pidof postgres| sed -r 's/ /,/g')"
1,395,122,243,000
I need to write a bash script wherein I have to create a file which holds the details of IP Addresses of the hosts and their mapping with corresponding MAC Addresses. Is there any possible way with which I can find out the MAC address of any (remote) host when IP address of the host is available?
If you just want to find out the MAC address of a given IP address you can use the command arp to look it up, once you've pinged the system 1 time. Example $ ping skinner -c 1 PING skinner.bubba.net (192.168.1.3) 56(84) bytes of data. 64 bytes from skinner.bubba.net (192.168.1.3): icmp_seq=1 ttl=64 time=3.09 ms --- s...
Resolving MAC Address from IP Address in Linux
1,395,122,243,000
Say I create a bridge interface on linux (br0) and add to it some interfaces (eth0, tap0, etc.). My understanding is that this interface act like a virtual switch with all its interfaces/ports that I add to it. What is the meaning of assigning a MAC and an IP address to that interface? Does the interface act as an add...
Because a bridge is an ethernet device it needs a MAC address. A linux bridge can originate things like spanning-tree protocol frames, and traffic like that needs an origin MAC address. A bridge does not require an ip address. There are many situations in which you won't have one. However, in many cases you may hav...
Why assign MAC and IP addresses on Bridge interface
1,395,122,243,000
After substantial research I still haven't found an answer to this query, how can I modify the command 'ifconfig' to show my computer's MAC address?
The command that you want on MacOS, FreeBSD, and TrueOS is: ifconfig -a link OpenBSD's ifconfig doesn't have this. Further reading ifconfig. Mac OS 10 Manual Pages. Apple corporation. 2008. ifconfig. FreeBSD Manual Pages. 2015. https://unix.stackexchange.com/a/319354/5132
How to view your computer's MAC address using 'ifconfig'?