what is the difference in output for ps -www and ps command in unix - bash

What is the difference between unix commands ps & ps -www, from man pages I saw this statement -w Wide output. Use this option twice for unlimited width., but when I use the -www I don't see any difference in output.
-bash-3.2$ ps 18451
PID TTY STAT TIME COMMAND
18451 ? Ds 1:02 ora_xxxx
-bash-3.2$ ps -www 18451
PID TTY STAT TIME COMMAND
18451 ? Ds 1:02 ora_xxxx

wide in the sense that it doesn't truncate output, not in the sense that it will output extra categories. Try it with ps -eF and ps -ewF and you will likely see the difference (depending on terminal size). If you instead want to display full output with more categories do ps -f or ps -F instead (or ps -o to specify which categories you want displayed)

Note that -ww gives you unlimited width, adding more ws does not make it longer.
One of my favourites is ps -efHww. It shows all processes as a hierarchy along with start time and consumed CPU time, with complete command lines.

Yes, there is a difference. You do not see any in your example, since the output is not wide enough. But if you have an output that exceeds a certain width (terminal width), then you will see a difference: the columns are not chopped any more. The result is that the output is wrapped over the line endings.

Related

How much memory is used by GradleWrapperMain and GradleDaemon processes

How much memory is used by GradleWrapperMain and GradleDaemon processes. I see 2 such processes being started for each of my application started with (nohup ./gradlew bootRun). This would help understand how much memory gets consumed by each App, as we are planning to run multiple Apps
jps
3494 GradleWrapperMain
2552 GradleWrapperMain
3530 GradleDaemon
10460 Jps
2588 GradleDaemon
Command jps hints at a Linux platform or equivalent. There does not seem to be a gradle command to check memory.
Shell command top allows to watch memory use as other resources. The m flag might be the most relevant.
You can check the actual memory consume terminal on follow way:
programmname="firefox" # replace "firefox" by your programname
top | grep "$programmname"
The order of the value output is:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
Replace the "firefox" by the name of programm which you are interested in.
Output the data like memory consume, of the program which you are interested in on terminal:
# Replace the xed by your programname
xed & pid=$!
# echo the pid of your program
echo $pid
# Start top and output the data like memory use
top -p $pid

Is there a way to see how much time remains on a timed process?

Is there a way to determine (in bash) how much time is remaining on a process that is running for a specified time?
For example, some time after executing
caffeinate -s -t 8000 &
is there a command or technique for determining when my system will be allowed to sleep?
Bash won't know that caffeinate has a timer attached to it; for all it knows, -t refers to the number of times you'll place an Amazon order of Red Bull before the process exits five minutes later.
If you know this, however, you can detect when the command was started and do the math yourself.
$ sleep 45 &
[1] 16065
$ ps -o cmd,etime
CMD ELAPSED
sleep 45 00:03
ps -o cmd,etime 00:00
/bin/bash 6-21:11:11
On OS X, this will be ps -o command,etime; see the FreeBSD ps man page or Linux ps docs for details and other switches/options.

BASH commands: pkill/pgrep

I'm struggling with understanding the difference between using pgrep, as opposed to using ps | grep.
Apart from the fact that pgrep will only list the PID, what is the difference?
When I run an instance of kwrite in the background of my terminal, as well as opening one up using the GUI, why is the output given by ps | grep kwrite only one PID, when two instances of kwrite are running?
On a slightly different note, why would using pkill to kill a crashed instance of kwrite not be a good way of killing a process? The only explanation that I could come up with, is that it would kill all processes with the string "kwrite" in them, and that may not be only the instance of kwrite I wanted to kill.
Thank you for your help.
ps | grep will fork 2 processes, pgrep only one.
ps | grep whatever may also list grep whatever depending when ps exits, pgrep whatever will not.
ps will need additonal command-line switches to show up both kwrite processes. (see: man ps and try ps -ef next time)
By default, ps selects all processes with the same effective user ID (euid=EUID) as the current user and associated with the same terminal as the invoker.
Try running a handfull kwrite instances, preferably with important and unsaved data to find out, why killing the crashed one using pkill might not be the most clever idea.

How to display list of processes sorted in reverse order for a bash, tsch, ksh shell in Unix

Was wondering if someone could help me with this... I want to display a list of running processes sorted in reverse order. The reverse order is to be based on process identification value - PID.
I was also wondering does it matter for the processes to be displayed in a certain shell? do I have to include something specific in the line of code or merely just change shells. I want to do this for both tsch and bash.
I have looked up the commands but I am not sure how to bring it together. See below:
ps = is the command that shows information about processes running in memory
-p = by process ID
r = running processes
sorting method?
Not sure how to bring it together.
Thanks for the help
This will do it:
ps aux | sort -k2 -rn
The ps command varies depending on OS. I can confirm the above will work in Linux and FreeBSD.
ps has it's own sort on linux, This is how I use it:
ps -eo pid,user,rss,vsz,pmem,comm,lstart --sort rss
In your case
ps aux --sort pid
In bash the following command will do it:
~$ ps aux --sort -pid | less
Normal (descending) order is achieved by specifying --sort pid or --sort +pid. The latter doesn't make much sense though.

How to examine processes in OS X's Terminal?

I’d like to view information for processes running in OS X. Running ps in the terminal just lists the open Terminal windows. How can I see all processes that are running?
Say I’m running a web browser, terminal and text editor. I’d like to see information for the text editor and web browser.
Running ps -e does the trick. Found the answer here.
You can just use top
It will display everything running on your OSX
Using top and ps is okay, but I find that using htop is far better & clearer than the standard tools Mac OS X uses. My fave use is to hit the T key while it is running to view processes in tree view (see screenshot). Shows you what processes are co-dependent on other processes.
You can install it from Homebrew using:
brew install htop
And if you have Xcode and related tools such as git installed on your system and you want to install the latest development code from the official source repository—just follow these steps.
First clone the source code from the htop GitHub repository:
git clone git#github.com:hishamhm/htop.git
Now go into the repository directory:
cd htop
Run autogen.sh:
./autogen.sh
Run this configure command:
./configure
Once the configure process completes, run make:
make
Finally install it by running sudo make install:
sudo make install
Try ps -ef. man ps will give you all the options.
-A Display information about other users' processes, including those without controlling terminals.
-e Identical to -A.
-f Display the uid, pid, parent pid, recent CPU usage, process start time, controlling tty, elapsed CPU usage, and the associated command. If the -u option is also used, display
the user name rather then the numeric uid. When -o or -O is used to add to the display following -f, the command field is not truncated as severely as it is in other formats.
Try the top command. It's an interactive command that will display the running processes.
You may also use the Apple's "Activity Monitor" application (located in /Applications/Utilities/).
It provides an actually quite nice GUI. You can see all the running processes, filter them by users, get extended informations about them (CPU, memory, network, etc), monitor them, etc...
Probably your best choice, unless you want to stick with the terminal (in such a case, read the top or ps manual, as those commands have a bunch of options).
To sort by cpu usage: top -o cpu
if you are using ps, you can check the manual
man ps
there is a list of keywords allowing you to build what you need. for example to show, userid / processid / percent cpu / percent memory / work queue / command :
ps -e -o "uid pid pcpu pmem wq comm"
-e is similar to -A (all inclusive; your processes and others), and -o is to force a format.
if you are looking for a specific uid, you can chain it using awk or grep such as :
ps -e -o "uid pid pcpu pmem wq comm" | grep 501
this should (almost) show only for userid 501. try it.
The slightly GUI way
if you are a cli (ui) fan. I recommend trying https://github.com/clementtsang/bottom which shows not only processes, but also temperature, disk usage and network. Screenshot is running from kitty (terminal) as an example, I use it on OSX default terminal and the color shows up a bit different, but still amazing.
The tree way
As described here : https://en.wikipedia.org/wiki/Pstree will give a better connection on the hierarchy of the processes
brew install pstree # if you need to install it
pstree
pstree -u <user> # show only processes by your user
pstree -s <string> # show only processes with string
pstree -help # show help

Resources