There is a field in process object in node.js: process.title
That field allows you to change process name displayed in top or ps command on linux.
Is there some way to do this for and in bash script also?
Changing the command line reference from running processes is possible on *NIX with /proc filesystem :
$ ps
PID TTY TIME CMD
106 tty4 00:00:01 bash
719 tty4 00:00:00 ps
$ echo "toto" > /proc/106/comm
$ ps
PID TTY TIME CMD
106 tty4 00:00:01 toto
719 tty4 00:00:00 ps
$
And yes, it's not the prettiest way to do so.
Related
I wanted to run an fsck check on my 5TB external hard drive on my raspberry pi.
This is the output:
$ sudo e2fsck -c -v /dev/sda
e2fsck 1.44.5 (15-Dec-2018)
Checking for bad blocks (read-only test): 0.46% done, 5:04 elapsed. (0/0/0 errors)
There has been zero progress for hours now. The elapsed time is stuck as well. This is actually my second attempt. Before I tried sudo e2fsck -p -c -v /dev/sda. This one doesn't give any output, that's why I let it run for a whole week before terminating.
My drive is unmounted, partitionless, and freshly formatted with mkfs.ext4. Output from ps:
$ ps -a
PID TTY TIME CMD
1075 tty1 00:00:00 bash
8404 pts/1 00:00:00 sudo
8405 pts/1 00:00:04 e2fsck
8446 pts/1 00:00:00 sh
8447 pts/1 00:00:05 badblocks
23605 pts/2 00:00:00 ps
I noticed on my first attempt, that it was impossible to send a SIGINT, SIGTERM, or SIGKILL to badblocks.
Why is this?
I am just trying to understand more about the PID column when running the ps command.
If I have two terminal windows open, in the first one I run the following command
firefox &
Then run the ps command in BOTH and get the following output from the first window
PID TTY TIME CMD
16814 pts/1 00:00:00 bash
16822 pts/1 00:00:04 MainThread
16881 pts/1 00:00:02 Privileged Cont
16938 pts/1 00:00:00 WebExtensions
17026 pts/1 00:00:00 Web Content
17081 pts/1 00:00:00 ps
And the following in the second
PID TTY TIME CMD
16794 pts/0 00:00:00 bash
17082 pts/0 00:00:00 ps
In both outputs we see the shell process. Why do they not have the same PID, even if it has the same process name.
I installed Cygwin for 64 bit versions of Windows.and I run "Cygwin64 Terminal" in order to confirm whole process' state. As far as I know, ps command must show STAT column but It is impossible to find STAT column Whenever I execute "ps -l" or "ps aux" ,"ps -ef", "ps axj"..
I really want to view STAT column in ps command because a source code which I practice recently request me to check zombie process by means of ps command.
screenshot of ps command without STAT column
Use procps
$ /usr/bin/procps.exe ax
PID TTY STAT TIME COMMAND
1580 pty1 Ss 0:00 -bash
1624 pty0 R 0:00 /usr/bin/procps ax
1522 ? Ss 0:05 /usr/bin/mintty -i /Cygwin-Terminal.ico -
1599 pty1 T 0:00 less .bashrc
1523 pty0 Ss 0:00 -bash
1579 ? Ss 0:00 /usr/bin/mintty -i /Cygwin-Terminal.ico -
you can find it in procps-ng package
$ cygcheck -f /usr/bin/procps
procps-ng-3.3.16-1
I know if I type ps -ef I get the processes. But how can I read the process tree of a user say xyz, so that I can draw it in hierarchal form?
Should I read the file path towards process and draw it as a tree structure? Or what?
Here is a selection from a larger ps -ef output:
UID PID PPID C STIME TTY TIME CMD
....
xyz 15152 15112 0 23:08:00 pts/19 0:00 usr/bin/bash
xyz 15112 15106 0 23:07:54 ? 0:00 /local/openssh/4.5p1/sbin/sshd -R
root 236 6535 0 21:27:06 ? 0:01 /local/openssh/4.5p1/sbin/sshd -R
xyz 15431 15152 0 23:09:30 pts/19 0:00 ps -ef
.....
How can I draw the process hierarchy of xyz?
Thanks
pstree [options] [pid or username];
see http://www.linfo.org/pstree.html and http://manpages.ubuntu.com/manpages/precise/man1/pstree.1.html
You can use htop -u USERNAME and then press F5
Please advice , how to verify the program that execute the process ?
For example
the following commands ( ps -ef ) will view the process sendmail in case this process is running
ps –ef | grep sendmail
root 9558 9544 019:05? 00:00:00/usr/sbin/sendmail-FCronDaemon-i-odi-oem-oi-t
what I want to find is the script that execute the binary /usr/sbin/sendmail
so my question – which flags I need to add to the syntax "ps –ef" in order to get from ps –ef the full details , include which program running the process
is it possible ?
Example and remark
If
/etc/rc3.d/sendmail run the binary /usr/sbin/sendmail
Then I expect to see the /etc/rc3.d/sendmail PATH from the command ps –ef …….
What do you need is a tree output and know the parent processes.
Example pstree -a:
[~]# pstree -a
init
├─atd
├─atop -a -w /var/log/atop.log 600
├─cron
├─dbus-daemon --system --fork --activation=upstart
├─getty -8 38400 tty4
│ ├─sshd
│ └─sshd
│ └─zsh
│ └─pstree -a
├─udevd --daemon
│ ├─udevd --daemon
│ └─udevd --daemon
├─upstart-socket- --daemon
├─upstart-udev-br --daemon
Here you can see that there is a process of zsh (my shell) which is running command pstree. The zsh itself was started by process sshd.
Here is the same output for ps -AF:
root 10006 649 0 22329 3944 0 12:48 ? 00:00:00 sshd: root#pts/2
root 10041 10006 0 10355 5276 0 12:48 pts/2 00:00:00 -zsh
root 16465 10041 0 4538 1220 0 12:52 pts/2 00:00:00 ps -AF
The second column is process id and the third column is parent process id. You see that the parent of ps -AF is the shell process 10041. You can always trace back processes to the init (process id 1) by walking them parent by parent.
In your case if you want to find /etc/rc3.d/sendmail you probably need to walk processes up from /usr/sbin/sendmail until you have something of which full path us under /etc/rc3.d.