recentpopularlog in

kme : processmanagement   30

bash - How to check if a process id (PID) exists - Stack Overflow
Looks like 'ps -p $PID' is the way to go; 'kill -0 $PID' has caveats.
unix  linux  sysadmin  processmanagement  shellscripting 
october 2019 by kme
How to setup trap in bash functions? - Unix & Linux Stack Exchange
Accepted answer suggests making function asynchronous (put it in the background?) and using 'wait'. I do not understand this.
Protip: Send the foreground process a QUIT with Ctrl-\ when Ctrl-C, -Z, -D aren't working.

Clear traps at the end of execution with trap - list of signals here

Fun on a non-production system: Try setting a trap for all sensible signals (e.g., not KILL). kill -l (not that's a lower-case L not a number 1 or pipe |)
bash  shellscripting  signals  processmanagement  tipsandtricks  reference 
april 2019 by kme
linux - how to kill the tty in unix - Stack Overflow | https://stackoverflow.com/
This was essentially what I needed
<code class="language-bash">ps -ft pts/6 -t pts/9 -t pts/10</code>

And my actual command line looked like this:
<code class="language-bash">
# probably could've done this with just 'who -al' instead of who + ps
who | grep userid \
| awk '{print $2}' \
| parallel 'ps -ft {} \
| tail -n +2' \
| awk '{print $2}'
| xargs kill -HUP</code>

And with some refinement, I was able to do something like this:
<code class="language-bash">
who -al | grep old \
| awk '{print $7}' \
| sudo xargs kill -HUP</code>

Also:
I had the same question as you but I wanted to kill the gnome terminal which I was in. I read the manual on "who" and found that you can list all of the sessions logged into your computer with the '-a' option and then the '-l' option prints the system login processes.
<code class="language-bash">who -la</code>

Also:
<code class="language-bash">pkill -9 -t pts/0</code>
unix  linux  sysadmin  pseudoterminal  processmanagement  solution 
march 2019 by kme
linux - How do I get "top" command to wrap its output? - Unix & Linux Stack Exchange
Just plain 'top -c' usually does what you want (which is to stop truncating the command name).
<code style="language-bash">top -bcn1 -w512</code>

The elegant solution is to use the option -w [number]. According to the man page, the maximum width is 512 characters, so you will need a different solution for anything exceeding that. Presumably you also want to see the full length of the commands, so use the -c option. We need to run top in "batch mode", -b, or it will continue to cut off the commands with a "+". Batch mode kind of makes a mess because it prints out all the jobs every second, so we can use the -n1 option to print out just one instance.
unix  linux  processmanagement  commandline  tui  annoyance  solution 
july 2018 by kme
linux - Force logout a user - Super User | https://superuser.com/
You terminate a session by killing its parent process, called the session leader. Find out which process it is with:

<code class="language-bash">ps -dN|grep pts/3</code>
unix  linux  sysadmin  usermanagement  processmanagement  tipsandtricks  maybesolution 
july 2018 by kme
How to: Linux Kill and Logout Users - nixCraft | https://www.cyberciti.biz/
The ultimate command to kill and logout all users is as follows: <code class="language-bash"># skill -KILL -v /dev/pts/*</code>
unix  linux  usermanagement  processmanagement  sysadmin  tipsandtricks 
july 2018 by kme
linux - Find pid of a certain ssh instance - Super User | https://superuser.com/
What I actually did was *not* put 'ssh' in the background (no '-f') and then capture the PID with '$!'.
Give pgrep a go:
<code class="language-bash">pgrep -f 'ssh .* -nNCTR'</code>
ssh  backgroundprocess  sshtunnels  processmanagement  unix  tipsandtricks  worksok  solution 
february 2018 by kme
mysql - How do I find which transaction is causing a "Waiting for table metadata lock" state? - Stack Overflow | https://stackoverflow.com/
All I actually had to do was stop the web server. The Flask-Admin web application had a lock on the table metadata, and I was trying to ALTER TABLE changing the data type/size of the columns. No go while the application was running, and that makes sense in retrospect.
If you cannot find the process locking the table (cause it is alreay dead), it may be a thread still cleaning up like this

section TRANSACTION of
<code class="language-sql">show engine innodb status;</code>

at the end
<code>---TRANSACTION 1135701157, ACTIVE 6768 sec
MySQL thread id 5208136, OS thread handle 0x7f2982e91700, query id 882213399 xxxIPxxx 82.235.36.49 my_user cleaning up</code>

as mentionned in a comment in Clear transaction deadlock?

you can try killing the transaction thread directly, here with
<code class="language-sql">KILL 5208136;</code>

worked for me.
dba  mysql  sql  processmanagement  solution  flask-admin 
february 2018 by kme
command line - What do the STAT column values in ps mean? - Ask Ubuntu
It's because I never think to search for "PROCESS STATE CODES" when I'm trying to find this in the manual page.
man ps has all the answers, under the "PROCESS STATE CODES" heading:

<code>
PROCESS STATE CODES
Here are the different values that the s, stat and state output specifiers (header "STAT" or "S") will display to describe the state of a process:
D uninterruptible sleep (usually IO)
R running or runnable (on run queue)
S interruptible sleep (waiting for an event to complete)
T stopped, either by a job control signal or because it is being traced.
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z defunct ("zombie") process, terminated but not reaped by its parent.

For BSD formats and when the stat keyword is used, additional characters may be displayed:
< high-priority (not nice to other users)
N low-priority (nice to other users)
L has pages locked into memory (for real-time and custom IO)
s is a session leader
l is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
+ is in the foreground process group.
</code>
reference  linux  processmanagement  ps  sysadmin  dammitbrain 
december 2017 by kme

Copy this bookmark:





to read