How to get the information of a specific process given its process ID using the command 'ps' in Linux - linux

How to get the information of a specific process given its process ID using the command 'ps' in Linux. I also want to get the proportion of memory the process occupies.
Is that 'ps processID' ?

You could use
pmap $PID
or perhaps
cat /proc/$PID/maps
and/or
cat /proc/$PID/status
See proc(5) for details.

ps -o pmem h -p processID
pmem: Ratio of the process's resident set size to the physical memory on the machine, expressed as a percentage.

Related

How to edit /proc/<pid>/limits file in linux?

I am trying to generate coredump for a particular pid.
I tried to change the core file size limit using ulimit, but it will change only in /proc/self/limits ( which is for shell).
So how do i edit it for particular pid?
Bascially i have to change "Max core file size=unlimited"
Note:
1)Our linux version dont have prlimit.
2)Even the below command didnt help
echo -n "Max core file size=unlimited:unlimited" > /proc/1/limits
Thanks,
prlimit
if you want to modify core_file limit, you can type
prlimit --pid ${pid} --core=soft_limit:hard_limit
the help page of prlimit is :
Usage:
prlimit [options] [-p PID]
prlimit [options] COMMAND
General Options:
-p, --pid <pid> process id
-o, --output <list> define which output columns to use
--noheadings don't print headings
--raw use the raw output format
--verbose verbose output
-h, --help display this help and exit
-V, --version output version information and exit
Resources Options:
-c, --core maximum size of core files created
-d, --data maximum size of a process's data segment
-e, --nice maximum nice priority allowed to raise
-f, --fsize maximum size of files written by the process
-i, --sigpending maximum number of pending signals
-l, --memlock maximum size a process may lock into memory
-m, --rss maximum resident set size
-n, --nofile maximum number of open files
-q, --msgqueue maximum bytes in POSIX message queues
-r, --rtprio maximum real-time scheduling priority
-s, --stack maximum stack size
-t, --cpu maximum amount of CPU time in seconds
-u, --nproc maximum number of user processes
-v, --as size of virtual memory
-x, --locks maximum number of file locks
-y, --rttime CPU time in microseconds a process scheduled
under real-time scheduling
Available columns (for --output):
DESCRIPTION resource description
RESOURCE resource name
SOFT soft limit
HARD hard limit (ceiling)
UNITS units
For more details see prlimit(1).
I always do this with ulimit command:
$ ulimit -c unlimited
On my Linux distro (ubuntu 16.04), core files are left on this directory:
/var/lib/systemd/coredump/
If your distro is based on systemd, you can setup this directory by modifiying pattern on this file:
$ cat /proc/sys/kernel/core_pattern
Please, read this info:
$ man 5 core
Check information related with /proc/sys/kernel/core_pattern.
As suggested previously, you can define the directory where all your core files are dumped, modifying the content of this file with "echo" command. For example:
$ echo "/var/log/dumps/core.%e.%p" > /proc/sys/kernel/core_pattern
This will dump all cores on /var/log/dumps/core.%e.%p, where %e is pattern for the executable filename, and %p pattern for pid of dumped process.
Hopefully you can play with this to customize your own needs.

Find ProcessorId and Cpu Usage of all running processes

Background
I want to find the cpu core id and utilization of each and every process running in my system.
I have used ps -eF to get cpu core id and ps -aux to get cpu utilization.
Query
I want to know, is there any way to get both the things using a single command or any specific options that is available in ps command to retrieve both the things?
You can add the -o option to your ps -ef to add additional columns to the output. The format specifiers are documented in the ps man page in the Standard Format Specifiers section.
For example:
ps -efo %cpu or ps -efo pcpu
Additionally, you can run this command to list all valid format specifiers:
ps L

What does this ps command do on Linux?

I try to get the output of the top 5 processes in a Linux system. I'm expecting to get the percentage of processor (CPU) used but I'm a little worried about if the command that I'm using gets the CPU or the RAM; what is the output?
ps -A --sort -rss -o comm,pmem | head -n 6
The man documentation of ps indicates that the output is the process, but I'm suspecting that is the RAM memory. Could you clarify the output for me, please?
It's a process sorting by rss which is resident set size - memory usage - and then showing you the command and percentage memory usage. Header line and top 5 processes.
For an explanation of what RSS actually is, see this answer on unix: https://unix.stackexchange.com/questions/35129/need-explanation-on-resident-set-size-virtual-size
To get the top 5 by CPU load as you asked:
ps -A --sort -pcpu -o comm,pmem,pcpu | head -n 6

How to get the memory size used by a process in Linux?

i want get the memory size used by a process in Linux. How can I do that?
ps aux --sort -rss
This will give you a listview of your Prozesses, Wortes by memory usage.
some useful commands to get memory info for a process:
pmap -x <PID>
top -p <PID>

Linux: memory usage summary for program

I need some command line utility able to run specified command and measure process group memory usage at peak and average (RSS, virtual and shared). As I understand that should be a combination of ptrace(2) and libprocps, but I can't find anything similar.
Any ideas?
/usr/bin/time -f "max RSS: %MKb" <command>
See man time for more details.

Resources