date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,358,935,391,000 |
I am running Linux Mint 18.2 with KDE Plasma. Recently I noticed that most of the times I copy large files to removable drives the process hangs just before finish.
I opened KSysGuard and saw that the process of file.so is in disk sleep.
When this happens the process seems not receiving any kill or end signal.
I decid... |
If a process is in an uninterruptible sleep state, then no, you cannot kill or otherwise end the process until it exits that state. While in that state, the process has invoked a system call on the kernel, and the kernel code executing on the behalf of the process has blocked the process waiting for some event to hap... | Is there any way to kill or end a process in "disk sleep" |
1,358,935,391,000 |
I have the pid and I just stopped a program using
kill -stop PID
Now I want to continue it by doing
kill -cont PID
But only if it's already stopped. How would I check to see if it's stopped or running?
|
You can check whether the process is in stopped state, T is ps output.
You can do:
[ "$(ps -o state= -p PID)" = T ] && kill -CONT PID
[ "$(ps -o state= -p PID)" = T ] tests whether the output of ps -o state= -p PID is T, if so send SIGCONT to the process. Replace PID with the actual process ID of the process.
| How can I check to see if a process is stopped from the command-line? |
1,358,935,391,000 |
Running newer versions of Gnome (on Wayland), you can't restart the shell with Alt+F2, entering r & then Enter - which used to restart the shell without logging the user out of the session.
More recently, on Fedora systems you used to be able to restart by sending SIGHUP to the gnome-shell process - using top or what... |
In an Xorg session one can restart GNOME shell without losing application state as applications are running against a separate server (X). But unlike Xorg in case of a Wayland session GNOME shell is not separate from the Wayland protocol, GNOME itself acts as the display server.
So there isn't any way to restart GNOM... | Restarting Gnome Shell 3.28.1 on Fedora 28 |
1,358,935,391,000 |
How does systemd handle the death of the children of managed processes?
Suppose that systemd launches the daemon foo, which then launches three other daemons: bar1, bar2, and bar3. Will systemd do anything to foo if bar2 terminates unexpectedly? From my understanding, under Service Management Facility (SMF) on Solaris... |
It doesn't.
The main process handles the death of its children, in the normal way.
This is the POSIX world. If process A has forked B, and process B has forked C, D, and E; then process B is what sees the SIGCHLD and wait() status from the termination of C, D, and E. Process A is unaware of what happens to C, D, and... | How does systemd handle the death of a child of a managed process? |
1,358,935,391,000 |
I've started a long running and machine hog process. I've hit CTRL-Z to stop it. I've then put it in the background with bg. Oops, I should have restarted with fg so that I could easily stop and start it again. What is the easiest way to stop a process that was just put into the background?
|
As noted, fg = foreground.
You can also try jobs to see them. Then %N can be used with fg or kill e.g. fg %4
| Undo bg; Undo putting a process into the background? |
1,358,935,391,000 |
I suspect this is not doable just because of the security implications, but here's what I'd like to do.
Basically we run a bash shell-script on our CentOS server that calls Program-A (in our case JMeter, but that is arbitrary) which runs and dumps data into a log file. After that process finishes the shell-script star... |
It looks to me as if you are trying to replace a RUNNING process from OUTSIDE the process. That's some radical stuff.
When I first looked at the question, it seemed that you are looking exactly for exec. But exec is called by the program itself. So unless you have coded the process so that you can force it to just exe... | Replace instance of process in place? |
1,358,935,391,000 |
When I start a graphical application from a terminal running bash, that application is somehow connected to that bash session. For example, when the applications dumps some text it will appear in the bash session it is started from. Also, some applications will get closed when i close the terminal using the close butt... |
The application is connected in two ways: to bash, and to the terminal.
The connection to the terminal is that the standard streams (stdin, stdout and stderr) of the application are connected to the terminal. Typical GUI applications don't use stdin or stdout, but they might emit error messages to stderr.
The connecti... | How is a graphical application started from a bash session connected to that bash session? |
1,358,935,391,000 |
When I'm launching a background process and then closes the terminal using the window's closing button, the background process gets killed. However if I close the terminal using Ctrl+D, the background process keeps running:
sam@Sam-Pc:~$ yes > /dev/null &
[1] 10219
// I then close the terminal a reopen a new one
sam@S... |
If you close the window using closing button, then a SIGHUP is sent to the background processes by the shell which also receives SIGHUP as the terminal closes. The normal response of the processes would be to exit, so the background jobs will be closed.
On the other hand if you press Cntl + D, no signal is sent rather... | Difference between closing the terminal using the closing button, and Ctrl-D |
1,358,935,391,000 |
This kills every process with a handle to file /foo/bar (in bash):
lsof /foo/bar 2>&1 | grep "/foo/bar" | sed "s/ */\\t/g" | cut -f 2 | while read PID; do kill $PID; done
This does not seem like such an uncommon task that there wouldn't be an easier solution, so I'm wondering if there's something like killall or a ... |
That's what -t is for. The man page even suggests you'd use that for kill.
lsof -t /some/file | xargs kill
Traditionally (before the lsof days), you'd use:
fuser /some/file 2> /dev/null | xargs kill
for that.
Some fuser implementations, like the one found on most Linux-based operating systems , Solaris or recent Fre... | Better way to kill all processes with a handle to some file |
1,358,935,391,000 |
I can not kill irq/${nnn}-nvidia by kill -9 or pkill -f -9.
Does anyone how to kill or stop those process?
(I am using Ubuntu 16.04, if that is relevant.)
|
As @hobbs explained, it is a kernel thread. A broader perspective is the following:
IRQ handling is problematic in any OS because interrupts can arrive at any time. Interrupts can arrive even while the kernel is in the middle of working on a complex task and resources are inconsistent (pointers are pointing to invali... | How do I kill an IRQ process in Linux? |
1,358,935,391,000 |
I have a gnome-run application in my home folder. I have now added the application to run when I press Meta+R (I added it in in CCSM). I run the application by executing ./gnome-run in my home folder.
I can't find any trace of the application process in the output of ps -A.
The problem is that if I have the gnome-run ... |
This shell script should handle the starting and stopping of any program:
#!/bin/bash
BASECMD=${1%%\ *}
PID=$(pgrep "$BASECMD")
if [ "$?" -eq "0" ]; then
echo "at least one instance of "$BASECMD" found, killing all instances"
kill $PID
else
echo "no running instances of "$BASECMD" found, starting one"
... | How do I check with a Bash script if an application is running? |
1,358,935,391,000 |
When I'm checking for some process, I usually write
ps aux | grep myprocess
And sometimes I get the output of
eimantas 11998 0.0 0.0 8816 740 pts/0 S+ 07:45 0:00 grep myprocess
if the process is not running.
Now I really wonder why grep is in the list of processes if it filters out the output of the p... |
This behavior is totally normal, it's due to how bash manages pipe usage.
pipe is implemented by bash using the pipe syscall. After that call, bash forks and replaces the standard input (file descriptor 0) with the input from the right process (grep). The main bash process creates another fork and passes the output de... | grep invading my ps [duplicate] |
1,358,935,391,000 |
I run 10+ different commands from 10+ different directories, and I need a better process to track everything.
I do a lot of debugging, and often times I need to work on multiple issues in parallel. I have lots of scripts that take 30-240 min to run, like:
create work area
compile code
run code to reproduce issue with... |
If the issue is you're finding it difficult to keep track of what you're working on as you bounce from task to task you might want to take the time to look at using a tool such as tmux and/or screen. These are virtual terminal window servers and allow you to setup a terminal within them and name it. This allows you to... | Best practices for job/process tracking and multi-tasking |
1,358,935,391,000 |
Gnome's system monitor has a "User" column in the Processes tab. There's also an "Owner" column, (that seems to be hidden by default).
Most of the processes have the same values on both columns. However, a few don't.
I was wondering what exactly does each column show, and what's the difference between the two.
|
systemd is a brand-spanking-new init system (it's about 4 years old, I believe). However, systemd encompasses much more than PID 1. Specifically, it happens to include a replacement for ConsoleKit, the old software that managed TTY sessions, X11 sessions, and really just logins in general. systemd's replacement for Co... | Process owner vs process user (Gnome's system monitor) |
1,358,935,391,000 |
One of the idioms often used to check if process is running is to use kill -s 0 $pid.
My question is, does it have any upsides over using [[ -e /proc/$pid ]] construct?
The script I'm writing is both Linux and bash specific.
|
I would prefer kill -s 0 pid vs testing /proc/pid as the former is portable, being specified by POSIX. Even if your script is targeting Linux, there is still a (very slight) risk for /proc to be unmounted for some reason.
| Using `kill -s 0 $pid` vs `[[ -e /proc/$pid ]]` to detect if PID is running |
1,358,935,391,000 |
I seem to have multiple bash processes running that are taking up most of my CPU. This is the output of top -c:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
20116 terdon 20 0 35288 14m 292 R 400.0 0.2 0:00.43 /bin/bash
20106 terdon 20 0 35992 15m 280 R 95.9 0... |
Take a look at the output of lsof | grep 'bash.*cwd'. That will tell you the current working directories of the processes.
If you have pstree, take a look at its output. If not, take a look at the output of ps aux -H. That will tell you which processes own these mystery processes.
Start looking through configuration f... | Mysterious bash instances using a lot of CPU, how can I debug? |
1,358,935,391,000 |
I have a script which starts a number of background processes and if works fine when called from the cmdline.
However the same script is also called during my xsession startup and additionally on some udev events. In both cases the background processes disappear.
I had put a sleep 10 into the script and I could see, t... |
Protect your processes with nohup:
nohup command-name &
You can also use this technique if you want to ignore stdout and stderr redirection to nohup.out:
command-name & disown
| Understanding when background process gets terminated |
1,358,935,391,000 |
This is more of a process management/signal handling question than a Bash question. It just uses Bash to explain the issue.
I'm running a Bash script in which I run a background process.
This is the script:
#!/bin/bash
# ...
# The background process
{
while :; do
sleep 1 && echo foo >> /path/to/some/file.txt
... |
So what does the man page tell us about huponexit?
If the huponexit shell option has been set with shopt, bash sends a SIGHUP to all jobs when an interactive login shell exits.
EDIT: Emphasizing that it is a LOGIN shell.
EDIT 2: interactive deserves equal emphasis
| A script's background process is still alive after closing the terminal |
1,358,935,391,000 |
For a while now, I have had the problem that a gzip process randomly starts on my Kubuntu system, uses up quite a bit of resources and causes my notebook fan to go crazy. The process shows up as gzip -c --rsyncable --best in htop and runs for quite a long time. I have no clue what is causing this, the system is a Kubu... |
Process tree
While the process is running try to use ps with the f option to see the process hierarchy:
ps axuf
Then you should get a tree of processes, meaning you should see what the parent process of the gzip is.
If gzip is a direct descendant of init then probably its parent has exited already, as it's very unli... | A gzip process regularly runs on my system, how do I figure out what is triggering it? |
1,358,935,391,000 |
I use recoll to index files and it kicks in a inopportune times.
When I use htop to change the view to a tree view using F5 and filter the process list I see a master process running and child processes underneath it. When I press F9 to choose a termination option it doesn't seem to respond to the SIGTERM option so I ... |
You can press Space to tag a process. The kill command applies to all tagged processes.
There's no easy way to tag a process and its children, but the tree view (t) should list them contiguously.
Depending on how recoll is run, the processes may be in their own process group. If they are, then you can use kill -STOP -... | How can htop be used to suspend a process and all its child processes? |
1,358,935,391,000 |
I start a new process from GNOME Terminal and then this process fork a child.
But when I killed the parent process the orphaned process's parent id became something other than 1 which represent init --user pid.
When I do this in virtual terminals, the parent pid is 1 which represent init process.
How can I execute ne... |
I already answered a similar question a few months ago. So see that first for technical details. Here, I shall just show you how your situation is covered by that answer.
As I explained, I and other writers of various dæmon supervision utilities take advantage of how Linux now works, and what you are seeing is that ... | Orphan process's parent id is not 1 when parent process executed from GNOME Terminal |
1,358,935,391,000 |
I ssh into a virtual server and start up a web server. Everything runs as expected. But when I close my terminal on my laptop, the process dies on the virtual server. How do I fix this?
|
You can use disown, it is a bash builtin:
disown [-ar] [-h] [jobspec ...]
Without options, each jobspec is removed from the table of active
jobs. If the -h option is given, each jobspec is not removed from the
table, but is marked so that SIGHUP is not sent to the job if the
shell receives a SIGHUP. If no jobsp... | How do I start a server via ssh and have it run after I log out? |
1,358,935,391,000 |
sudo ps o gpid,comm reports something like 3029 bash but the command has parameters --arbitrary -other -searchword is there a way to display these arguments?
|
Rather than formatting the output of ps and then using grep, you can simply use pgrep with -a option:
pgrep -a bash
This will show the command name (bash) along with its arguments (if any).
From man pgrep :
-a, --list-full
List the full command line as well as the process ID.
| How to find and print arguments of a command in ps? |
1,358,935,391,000 |
For example:
$ cat foo.sh
#!/usr/bin/env bash
while true; do sleep 1 ; done
$ ./foo.sh &
$ pgrep foo.sh
$
Contrast with:
$ cat bar.sh
#!/bin/bash
while true; do sleep 1 ; done
$ ./bar.sh &
$ pgrep bar.sh
21202
The process started by env bash shows up in the output of ps aux as:
terdon 4203 0.0 0.0 26676 6340 pts... |
Q#1
Why does the name of the script not show up when called through env?
From the shebang wikipedia article:
Under Unix-like operating systems, when a script with a shebang is run
as a program, the program loader parses the rest of the script's
initial line as an interpreter directive; the specified interpreter... | Why can't pgrep find scripts started via env? |
1,358,935,391,000 |
Looking through syslog, I see lines like dd invoked oom-killer.
Does this mean dd is being killed by the oom-killer or does it mean dd asked oom-killer to go kill another high memory process?
|
dd triggered OOM killer, which, in turn, killed a process with the highest OOM score.
| Does a process invoking oom-killer kill itself? |
1,358,935,391,000 |
I was trying to change linux process priority using chrt. I changed priority of one process to SCHED_FIFO from SCHED_OTHER. I could see some improvement in the perfomance. I run linux angstrom distribution for my embedded system.
So if I use SCHED_FIFO for one process, how other process will get affected? What are th... |
As explained in sched_setscheduler(2), SCHED_FIFO is RT-priority, meaning that it will preempt any and all SCHED_OTHER (ie. "normal") tasks if it decides it wants to do something.
So, you should be absolutely sure it is well written and will yield control periodically by itself, because if it decides not to (eg. it wa... | SCHED_FIFO and SCHED_OTHER |
1,358,935,391,000 |
For long running processes like init, I can do things like
$ cat /proc/[pid]/io
What can I do if I want to see stats for a briefly running process such as a command line utility like ls? I don't even know how to see the pid for such a briefly running process...
|
Basically, it sounds like you want general advice on profiling an application's I/O at runtime. You've been doing this with /proc/$PID/io which will give you some sort of idea of how much bandwidth is being used between disk and memory for the application. Polling this file can give you a rough idea of what the proces... | How can I see i/o stats for a briefly running process? |
1,454,631,843,000 |
I am writing a wrapper application to bash scripts and want the application to keep a track of which tools/processes have been launched from user scripts. I would like to know what is the best way to determine the list of child processes that were spawned of this parent process.
I tried
Periodically invoking ps comm... |
If you're using Linux, you can use strace to trace system calls used by a process. For example:
~ strace -e fork,vfork,clone,execve -fb execve -o log ./foo.sh
foo bar
~ cat log
4817 execve("./foo.sh", ["./foo.sh"], [/* 42 vars */]) = 0
4817 clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHL... | Get list of processes that were forked off my currently running process? |
1,454,631,843,000 |
Say you're in a directory and you want to check something in another directory, so you type bash to spawn a new shell so you can cd and check that thing and then type exit to get out and go back to the original shell still in that old directory.
Is there any way to keep both bashes running and switch between the two, ... |
You can use the suspend command to background the child shell and return to the parent shell.
| Intelligently switch between multiple BASH processes |
1,454,631,843,000 |
What the multiprocessing model for Linux? Is there a default or most commonly used model? Is it similar or very different from say BSD or even the MS Windows kernel?
If SMP is used normally, can assymetric be used instead if desired?
|
From Wikipedia:
Asymmetric multiprocessing (AMP) was a software stopgap for handling
multiple CPUs before symmetric multiprocessing (SMP) was available.
Linux uses SMP.
| What is the default or most commonly used multiprocessing model in Linux? Symmetric or Asymmetric? |
1,454,631,843,000 |
How do you start a process that cannot do any file IO (opening / closing files, creating / deleting files, reading / writing files, etc.), except to read and write to pre-created FIFOs?
(chroot will not work because the process can break out of it, but messing with / modifying the kernel and such is okay)
BTW: I canno... |
If
the program can be modified to make a system call of your choice before any of the untrusted code (this might be done via LD_PRELOAD), and
the program doesn't need to do any system calls beyond exit(), sigreturn(), read() and write()
then you can use seccomp (Wikipedia article). To allow for more that just those... | Disallow File IO for a process except for FIFOs |
1,454,631,843,000 |
I was wondering how many processes can I create on my machine (x64 with 8Gb of RAM and running Ubuntu). So I made simple master process which was continiously creating child processes, and that child processes were just sleeping all the time. I ended with just 11-12k processes. Then I switched processes to threads and... |
I think you hit either a number of processes limit or a memory limit.
When I try your program on my computer and reach the pid == -1 state, fork() returns the error EAGAIN, with error message: Resource temporarily unavailable. As a normal user, I could create approx 15k processes.
There are several reasons this EAGA... | What is a limit for number of threads? |
1,454,631,843,000 |
I've noticed, that all mate-terminal instances I start, be it inside a mate-terminal or via a link button, have the same PID.
For example, I got something like
$ wmctrl -lp
<omitted lines that don't matter>
0x03c0001f 1 7411 <hostname> Terminal
0x03c06b9f 1 7411 <hostname> Terminal
0x03c07349 1 7411 <hos... |
All the instances of Mate Terminal have the same PID because they are in fact a single process which happens to display multiple windows. Mate Terminal runs in a single process because that's the way the application is designed. When you run the command mate-terminal, it contacts the existing process and sends it an i... | Why do multiple instances of Mate-terminal have the same PID? |
1,454,631,843,000 |
Circumstances
I'm having a lecture on "Cloud Security" at University, and am currently doing a project on virtual machine introspection.
Goal of my exercise was to escalate privileges of some process to root privileges, which I accomplished by "borrowing" the pointer to struct cred from init, using volatility and libv... |
Tasks do not have a struct cred. They have two struct cred's:
* A task has two security pointers. task->real_cred points to the objective
* context that defines that task's actual details. The objective part of this
* context is used whenever that task is acted upon.
*
* task->cred points to the subjective con... | Where are UID/GID of a process from, when not from the process's cred pointer? |
1,454,631,843,000 |
I am kind of new with bash and have been playing with it on and of for about a month.
While trying to understand how nested command groups work, I tried the following command:
((ps j; ps j); ps j; ps j)
Now, what I was expecting is that the nested group would produce a separate process group with a new bash shell a... |
As a first guess, I would assume that subshells started with ( .. ) don't use job control, in the same way that noninteractive scripts don't. However, $- seems to contain the m for job control even inside parenthesis (as well as i for interactive):
$ echo $-
himuBs
$ bash -c 'echo $-'
hBc
$ ( echo $-; )
himuBs
But I ... | Nested command groups do not produced nested process groups? |
1,454,631,843,000 |
I have been in a situation where my desktop has crashed and become unresponsive. (In my case it was the Cinnamon DE, and I have yet to try cinnamon --replace from the commandline, BTW)
I was using a download manager type GUI app to download a large file, and it was clear that the process was still running quite happil... |
In theory, a program that loses its connection to the X server could just try reconnecting until a new X server is available. In fact, I've written programs that do this. It requires extra code, because you have to re-run your GUI-initialization routine to re-create your resources (windows, bitmaps, fonts, etc) on t... | Can I attach a GUI process to a "surrogate X server"? |
1,454,631,843,000 |
I have a shell-wrapper around a large executable. It does something like this:
run/the/real/executable "$@" &
PID=$!
# perform
# a few
# minor things
wait $PID
# perform some
# post-processing
One of the things it does after the wait is check for core-dumps and handle process the crashes, however, by then the process... |
As far as I know, there are no shell methods to do what you're trying, it will have to be done from a custom program.
Use ptrace() to monitor the process, similar to the way a debugger does. When the process receives a signal, it will be stopped, and the monitoring program will be notified (its call to wait() will ret... | Can a Linux-process intercept signals sent to its child? |
1,454,631,843,000 |
I am working on some batch scripts involving the following:
Run some non-terminating sub-processes (asynchronously)
Wait for t seconds
Perform other task X for some time
Terminate subprocesses
Ideally, I would like to be able to differentiate the stdout of the sub-processes which has been emitted before X from that... |
While you could complicate the matter with exec and extra file descriptor wrangling, your second suggestion is the simplest. Before starting X, echo a marker string into the log file.
All those commands would be appending to the same file, so maybe it would be a good idea to prepend all output of X with a marker, so y... | Discard stdout of a command for t seconds |
1,454,631,843,000 |
I want to write a script that will detect whether a particular desktop application is responding and kill it. Is this possible?
I know I've seen the GNOME desktop put up a "Application is not responding" dialog, and I figure it sends some sort of signal to the window and waits a certain amount of time for a response. ... |
I can comment on Gnome's "Application is not responding" dialog, but not directly answer your question.
It seems that both Metacity and Mutter use meta_display_ping_window() function to determine the status of a window (read the doc comment in display.c).
The default timeout PING_TIMEOUT_DELAY is 5 s. Ping-timeout an... | How to detect a desktop application hanging |
1,454,631,843,000 |
Is it possible to run a Java process in Linux in a way that it could be seen in ps as some sort of alias? It would be easier to restart it when it is down.
|
Try Java Virtual Machine Process Status Tool(jps):
[Tue Aug 30@17:02:14][prince@localhost ~]$ jps -l
30207 sun.tools.jps.Jps
29947 org.netbeans.Main
| How to run java process to be seen not as 'java...' in processes list? |
1,454,631,843,000 |
I am trying to set up a Thin Ruby application server on my Ubuntu VPS. I have created a specific account, installed rbenv under it along with all gems.
I am looking for a convenient way to obtain the following objectives:
Run my Thin Rack application under my non-privileged user account.
Make the application run as a... |
For starting at boot time add a line to your users crontab file (using crontab -e):
@reboot /path/to/your/script with parameters
The actual contents of that script vary with your needs. It might just start the daemon, or it might start a somewhat more intelligent agent that you pass a configuration. That way you can h... | Running a daemon as a non-privileged user |
1,454,631,843,000 |
From the book Advanced programming in the Unix environment I read the following line regarding threads in Unix like systems
All the threads within a process share the same address space, file
descriptors, stacks, and process-related attributes.Because they can
access the same memory,the threads need to synchroniz... |
In the context of a Unix or linux process, the phrase "the stack" can mean two things.
First, "the stack" can mean the last-in, first-out records of the calling sequence of the flow of control. When a process executes, main() gets called first. main() might call printf(). Code generated by the compiler writes the addr... | What is meant by stack in connection to a process? |
1,454,631,843,000 |
I want to find the sessions which only have dead panes, to then kill them. How do I do this?
|
You can list all panes and then filter by dead panes:
tmux list-panes -a -F "#{pane_dead} #{pane_id}" | grep "^1"
And you can kill them with
tmux kill-pane -t PANE_ID
combine this into:
tmux list-panes -a -F "#{pane_dead} #{pane_id}" | \
awk '/^1/ { print $2 }' | xargs -l tmux kill-pane -t
| tmux: Find all sessions that only have dead panes |
1,454,631,843,000 |
I was wondering if the Process Table in linux OS has a limit.
Can it get full? And if so, what would I do to make space (maybe try deleting entries for zombie processes) ?
|
Run sysctl kernel.pid_max kernel.threads-max to see the current maximum limits for processes and threads respectively. (Each process occupies at least one thread; more if multithreaded.)
The "factory default" process limit might be 32768 on desktop-oriented distributions, or something rather higher in enterprise-orien... | Process table limit |
1,454,631,843,000 |
I have a bug in my Linux app that is reproducable only on single-core CPUs.
To debug it, I want to start the process from the command line so that it is limited to 1 CPU even on my multi-processor machine.
Is it possible to change this for a particular process, e.g. to run it so that it does not run (its) multiple thr... |
You can use taskset from util-linux.
The masks
may be specified in hexadecimal (with or without a leading "0x"), or as
a CPU list with the --cpu-list option. For example,
0x00000001 is processor #0,
0x00000003 is processors #0 and #1,
0xFFFFFFFF is processors #0 through #3... | Run process as if on a single-core machine to find a bug |
1,454,631,843,000 |
I am reading some Linux documentation about 'signals' and I still have these questions making noise in my mind:
1) A 'signal' handler execution is done when the 'target' process receives its execution token from the Scheduler?
2) Or 'signal' handler execution takes place in whatever process 'context' happens to be exe... |
1) The signal handler is executed the next time the target process returns from kernel mode to user mode.
This occurs either when the process is scheduled to run again after a hardware interrupt (and it wasn't already running in kernel mode), or when the process returns from a system call (on some architectures, these... | Signal execution details |
1,454,631,843,000 |
Is there an existing tool for solaris/unix that keeps a history trail of the list of running processes. I'd like to be able to review backwards in time what processes were active/running.
I can create a cron job that just regularly logs the output of ps into files, but this is crude and over a large server farm seems ... |
Use auditing.
Solaris Auditing (Overview)
Auditing generates audit records when specified events occur. Most
commonly, events that generate audit records include the following:
System startup and system shutdown
Login and logout
Process creation or process destruction, or thread creation or thread destruction
Open... | Is there a process logging tool for solaris? |
1,454,631,843,000 |
If I ssh to a box and start a task that will take some time to complete I usually press control+z to pause the process, and then immediately type bg 1 to put run it in the background.
I can then type jobs and see it running.
If I disconnect (type exit, press control+d, etc) and then log back in, I can no longer type j... |
You can use kill -STOP pid to pause a job and kill -CONT pid to resume it. You get the proper pid from the ps command you already know.
| How can I manage jobs after I disconnect from my tty/ssh session? |
1,454,631,843,000 |
Possible Duplicate:
How to check how a long a program has been running?
I am interested in doing this purely using bash.
|
ps can fit your needs:
ps -eo pid,command,etime
To get information for a specific process:
ps -o command,etime -p PID
| How to know how long a process has been running? [duplicate] |
1,454,631,843,000 |
I am running some test on Amazon EC2 instances and we want to make the CPU always busy at above 80%.
What I have is a program main that needs to run in high priority and I want to launch another program, preferably some math C code or a bash script that loads the CPU to over 80%.
What programs are there to use for suc... |
Occupying one CPU at 100% (minus overhead) is easy in the shell:
while true; do :; done
If you want to reduce the load, introduce sleeps.
i=0; while [ $i -ne 0 ] || sleep 0.001; do i=$(( (i+1) % 10000 )); done
Tune 10000 up or down to get the desired load.
The scheduling priority is set by nice. You'll need to be ro... | Program to test CPU load and process priority |
1,454,631,843,000 |
I terminated the gnome-pty-helper process with
$ kill -9 9753
After a while it was running again with another process number.
There wasn't a restart of a system.
Why is it located under ~/.config/gnomy-pty-helper?
$ file gnome-pty-helper
gnome-pty-helper: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux)... |
gnome-pty-helper is automatically started by the VTE library when necessary. If you want to avoid its running (why?), you should avoid using anything built with the VTE library (libvte*).
The elements you’ve added recently make this look more like a compromise of some sort: ~/.config shouldn’t contain binaries, and gn... | Prevent gnome-pty-helper from running again |
1,454,631,843,000 |
I read that their is 1:1 mapping of user and kernel thread in linux
What is the difference between PTHREAD_SCOPE_PROCESS & PTHREAD_SCOPE_SYSTEM in linux if kernel is considering every thread like a process then there will not be any performance difference? Correct me I'm wrong
|
According to the man page:
Linux supports PTHREAD_SCOPE_SYSTEM, but not PTHREAD_SCOPE_PROCESS
And if you take a look at the glibc's implementation:
0034 /* Catch invalid values. */
0035 switch (scope)
0036 {
0037 case PTHREAD_SCOPE_SYSTEM:
0038 iattr->flags &= ~ATTR_FLAG_SCOPEPROCESS;
0039 ... | Pthread scheduler scope variables? |
1,454,631,843,000 |
I have some confusion as to what's the correct value to use for the number of CPU's I can use to make a CPU_SET for a sched_setaffinity call on my system.
My /proc/cpuinfo file:
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 37
model name : Intel(R) Core(TM) i5 CPU M 460 @ 2.53GHz
ste... |
Your CPU is a dual core CPU with hyperthreading Intel® Core™ i5-460M Processor
This means you have 2 cores and they are physical CPU's.
You have also hyperthreading and so you have 4 logical CPU's.
taskset was designed because the balancing of tasks in a multicore CPU was a performance lost. The tasks did normally n... | What's the correct value to base the maximum number of CPU's to sched_setaffinity to? |
1,454,631,843,000 |
After a process has been terminated, is it possible to retrieve any information about it, such as when it started and finished, &c.
Is it possible to enable logging of this information?
|
In general, only if you log it at the time. Probably the most straightforward way would be to use the kernel's auditing features using auditd, and configure the system calls that you care about logging.
| What information about a process is retrievable after it is terminated? |
1,454,631,843,000 |
I've been studying process management using shell scripts and I'm starting to realise how difficult it is to make sure that it's done right.
For example, you can record the PID of a program to a file, wait on it, and clean up the PID file after the program exits.
If you were to try and kill this daemon from an init sc... |
You are correct to suspect that there is a (small!) atomicity problem.
No matter what method you use, whether it's a system-standard utility like start-stop-daemon, a roll-your-own PID file, using pkill to query and kill by user ID, by executable binary, or whatever, there is always an interval between finding what pr... | Process management and pkill |
1,454,631,843,000 |
I figured out that the number of context switches performed by a process can be found in /proc/$$/status. I have been trying to look for the total number of context switches performed since bootup.
I tried doing grep context * | grep switch while in /proc, and got the following output
...
kallsyms:0000000000000000 t x... |
The number of switches performed by each processor can be found in proc/sched_debug.
The output of grep nr_switches * is
...
sched_debug: .nr_switches : 2652089
sched_debug: .nr_switches : 2677660
sched_debug: .nr_switches : 2778421
sched_debug: .nr_switches ... | Where does one find the total number of context switches performed since bootup? |
1,454,631,843,000 |
I have some doubts about setting the policy of a thread and how that policy is going to be followed while it is executing. Pthread allows setting the scheduling policy of a thread to SCHED_FIFO/SCHED_RR/SCHED_OTHER. I am trying to understand how this user-set-policy works as the Linux kernel uses CFS as the default sc... |
A/ BASIC THEORY 3: CFS is not the default "scheduler policy" under Linux. CFS is the default scheduler under linux.
A scheduler chooses among all existing threads those to which cpu time should be granted.
This choice is governed by miscellaneous parameters that are taken into account differently depending on the sche... | Scheduling policy of a POSIX thread Vs kernel's Completely Fair Scheduler when the thread is actually executing |
1,463,169,850,000 |
I have a javascript program, which runs on nodejs. If I run the following command:
node app.js
It keeps running but sometimes it exits. But I want to start it again automatically when it exits.
Is there any command to do so for Linux systems? Note that I don't want to use cron jobs.
|
Quick and dirty way : If using bash then what about a simple bash script like :
#!/usr/bin/bash
while true
do
node app.js
done
BTW, this is wrongdoing since you don't take into account the reasons why your task exited and there might be very good reasons for not restarting it. Not to say that it could also crash at... | Automatically restart a process after it exits |
1,463,169,850,000 |
I'm trying to obtain the processID of pcmanfm like this:
pgrep -f "pcmanfm"
When pcmanfm is not running, the command above returns nothing (as I expect).
However, when I run the command from python, it returns a process ID even when pcmanfm is not running:
processID = os.system('pgrep -f "pcmanfm"')
Furthermore, if ... |
Proposed solution:
Remove the -f option from your pgrep command.
Explanation:
You probably get the process ID of the shell that is executed to run your command. A new shell process with a new PID will be created for every system.exec_command.
Run e.g. sh -c 'pgrep -af nonexistent' and check the output. You will proba... | Autokey - Focus App Window If Running, Launch App If Not |
1,463,169,850,000 |
I have some conditions for some background job to run:
condition-command && condition-command && background-job &
The problem is: I want the conditions to block until the job runs, as if I had run:
condition-command; condition-command; background-job &
But it isn't a condition, if previous command fails I do not wan... |
If you don't want the background to apply to the whole line, then use eval:
sleep 2 && eval 'sleep 10 &'
Now only the second command will be a background job, and it will be a proper background job that you can wait on.
| Why double ampersand chained conditions runs in background together the last one? |
1,463,169,850,000 |
I'm on an OpenVZ VPS and I created a background process as a non-root user then disowned it i.e.
user@server:~$node server.js &
user@server:~$disown
I SSH'ed out of the VPS and now I'm back in but I can't seem to kill the process using its PID. Pkill 1292. It even fails as root.
I know its not dead because when I ru... |
pkill (like pgrep which uses the same interface, initially a Solaris command, now found on many other unix-likes including Linux (procps package)) is to kill processes based on their name.
pkill regexp
kills (sends the SIGTERM signal) to all the processes whose name¹ matches the given regular expression.
So here pkil... | How to kill a process that's not attached to any terminal |
1,463,169,850,000 |
I run both regular Chrome and Chrome Canary (from now on, Canary). Sometimes I want to kill all subprocesses, Google Chrome Helper, of Canary. The problem is that they have the same name as the subprocesses of regular Chrome so killall "Google Chrome Helper" would kill both Canary's and Chromes' subprocesses.
How can,... |
Try using the -P option of pkill:
-P ppid Restrict matches to processes with a parent process ID in the
comma-separated list ppid.
| How can I kill all child processes of a certain process from the command line? |
1,463,169,850,000 |
I have process which created multiple PID's. I want to kill all those PID's. I have tried
pkill <process_name>.
But PID not getting killed as they were wait to resource releasing.
I have managed to get PID list with
ps -ef | grep <process_name> | awk '{print $2}'
which gives process ID list but how can I kill all ... |
You could pipe the output to xargs e.g.
ps -ef | grep <process_name> | awk '{print $2}' | xargs /bin/kill
But why doesn't your pkill command work?
| How to kill line of PID? |
1,463,169,850,000 |
I am looking for a reliable cross-platform way to check if a process with a specific pid is running. Two possible solutions came up:
kill -0 $PID — exit status is 0 if it the process exists and 1 if not, however it also returns 1 for pids that require additional privileges to kill.
ps a | grep "^\s*${PID}" and simil... |
Can you write a small C program? The kill(2) system call does return -1 if your UID doesn't have permission to send a signal to a given process, but errno is set to EPERM in that case, as opposed to ESRCH for a non-existent PID. I'm reasonably certain you could make it portable across Solaris, HP-UX, Linux and the *B... | Cross-platform (Linux, BSD, Solaris) way to check if pid exists |
1,463,169,850,000 |
I want to run an interactive tool that can either exit by itself (when the tasks are done) or by me hitting Ctrl+C. In this example, the tool consists of an echo and a sleep (thus it is not really interactive any more).
I need some more monitoring around it, so I would do
echo "$(date) Starting!" | tee -a myLog.log; \... |
If I understand you correctly:
#!/bin/sh
trap catchSigint INT
catchSigint(){
echo
echo "$(date) Interrupted" | tee -a myLog.log
exit 1
}
echo "$(date) Starting!" | tee -a myLog.log
echo "I NEED SOME TIME"
sleep 10
echo "$(date) Ended" | tee -a myLog.log
See that we are trapping SIGINT (triggered by Ctrl+C... | How can I prevent Ctrl+C from "going outwards"? |
1,463,169,850,000 |
How can I terminate a process upon specific output from that process? For example, running a Java program with java -jar xyz.jar, I want to terminate the process once the line "Started server on port 8000" appears on stdout.
|
That can be accomplished with the following script considering that grep -m1 doesn't work for you:
#!/bin/bash
java -jar xyz.jar &> "/tmp/yourscriptlog.txt" &
processnumber=$!
tail -F "/tmp/yourscriptlog.txt" | awk '/Started server on port 8000/ { system("kill '$processnumber'") }'
Basically, this script redirects ... | Terminate process upon specific output |
1,463,169,850,000 |
As we know, the lsof can know which file/directory is take up by process. But I want to capture a command process to judge which file/directory the command will call.
For example,the useradd will call the /etc/passwd and etc/shadow,the lastb will call the /var/log/btmp. Of course,some programs may conditionally open f... |
strace may be of interest.
# strace -fe open useradd bob
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/lib64/libaudit.so.1", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib64/libselinux.so.1", O_RDONLY|O_CLOEXEC) = 3
open("/lib64/libacl.so.1", O_RDONLY|O_CLOEXEC) = 3
open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
o... | How to capture a command process |
1,463,169,850,000 |
This is the situation:
I have a PHP/MySQL web application that does some PDF processing and thumbnail creation. This is done by using some 3rd party command line software on the server. Both kinds of processing consume a lot of resources, to the point of choking the server. I would like to limit the amount of resource... |
Run it with nice -n 20 ionice -c 3
That will make it use the remaining CPU cycles and access to I/O not used by other processes.
For RAM, all you can do is kill the process when it uses more than the amount you want it to use (using ulimit).
| How to constrain the resources an application can use on a linux web server |
1,463,169,850,000 |
Everybody knows that PID number 1 is systemd (or something equivalent). And every process after that takes another PID, counting up.
However when there are 50 processes running (up to PID 50) and the process with PID 2 terminates and a new process starts, it won't be PID 2, but it will be PID 51. Why is that?
I notic... |
Most Unix variants allocate process IDs sequentially: 1, 2, 3, 4, ... When the largest possible PID value is reached, they start again at 1, skipping PIDs that already exist.
This is not an obligation. For example, OpenBSD assigns PIDs randomly, not sequentially; this is also an option on FreeBSD. The goal is improve... | Why do processes not fill up empty process IDs |
1,463,169,850,000 |
I executed a command like this: nohup some_command &. Now this command is in the background. I can see it with the command jobs.
Example output:
[1]+ Running nohup some_command &
Is it somehow possible to have a live representation of the status that comes from the jobs command, similar to how top wo... |
If all you want is for job completion notifications to be printed immediately, even if you're at typing a prompt or if some other job is in the foreground, then just run set -o notify.
If you want a foreground command that displays the status of background jobs from the current shell, you can run jobs in a loop. It's ... | Live monitoring of background jobs |
1,463,169,850,000 |
I would like to spawn a persistent netcat server. My command of choice is the following:
echo "bash -c \"while [ 1 ]; do nc -l -p 1111 >> check; done\"" | at now
I am wondering how I can get the PID of the process created by at so that I can easily put the server to sleep when needed.
|
This is a tad tricky because of quoting, note change from " to '
The following will work if you submit your at job via at -f file
at -f nc.on now
cat nc.on
bash -c 'while [ 1 ]; do echo $$ > /var/run/atnc.pid; nc -l -p 1111 >> check; done'
the file /var/run/atnc.pid will have the process id of the bash which is runn... | Get pid of long running command executed via at |
1,463,169,850,000 |
A Linux thread or forked process may change its name and/or its commandline as visible by ps or in the /proc filesystem.
When using the python-setproctitle package, the same change occurs on /proc/pid/cmdline, /proc/pid/comm, the Name: line of /proc/pid/status and in the second field of /proc/pid/stat, where only cmdl... |
All three entries are defined close together in the kernel source: comm, stat, and status. Working forwards from there, comm is handled by comm_show which calls proc_task_name to determine the task’s name. stat is handled by proc_tgid_stat, which is a thin wrapper around do_task_stat, which calls proc_task_name to det... | Thread Name: Is /proc/pid/comm always identical to the Name: line of /proc/pid/status and the second field of /proc/pid/stat? |
1,463,169,850,000 |
I have a script that looks like this. Invoked with ./myscript.sh start
#!/bin/bash
if [[ "$1" == "start" ]]; then
echo "Dev start script process ID: $$"
cd /my/path1
yarn dev &> /my/path/logs/log1.log &
echo "started process1 in background"
echo "Process ID: $!"
echo "Logging output at logs/log1.log"
sl... |
You could get the list of processes directly spawned from that bash and send SIGTERM to them:
pkill -P $$
$$ is the process number of the current bash script.
Depending on how the signal is treated by the child processes, that might or not kill the grandchild processes (and so on, recursively).
So another way to do i... | How do I kill all subprocesses spawned by my bash script? |
1,463,169,850,000 |
If I have the following jobs running in a shell
-> % jobs -l
[1] 83664 suspended nvim
[2] 84330 suspended python
[3] 84344 suspended python
[4] 84376 suspended nvim
[5] - 84701 suspended python
[6] + 84715 suspended python
How can i return to the nth job, suppose I want to return to job 4, or job ... |
To return to job 4, run:
fg %4
The command fg tells the shell to move job %4 to the foreground. For more information, run help fg at the command prompt.
When you want to suspend the job you are working on, run bg. For more information, run help bg at the command prompt.
For more detail than you'd likely want to kno... | Return to a particular job in the jobs list |
1,463,169,850,000 |
I was wondering if there was a program like GNU/screen or tmux that would allow me to attach or detach a session with a running process but would not provide all of the other features such as windows and panes. Ideally the program would be able to run in a dumb terminal (a terminal without clear).
My use case is to u... |
dtach is a wafer-thin terminal session manager, now forked on github, or doubtless easily installed via the ports or package system for your operating system.
(Of historical interest may also be the dislocate example script distributed with expect.)
| Is there a program like tmux or screen but only for attaching or detaching a session |
1,463,169,850,000 |
I knew how to suspend one process and bring it into foreground in current shell, but I have no idea about that If I have run a process in shell A and now I want to bring it into foreground in current shell B.
Without using third tools like screen, does there exist a way to do this task?
In my opinion, I think it shoul... |
There are usually 2 things you would need to do to get this effect:
Reparent the process to a new shell.
There is basically no way to do this as far as I know. In UNIX, there is only one way to reparent a process that I know about, and that happens only when its original parent dies without waiting for it. In that ca... | Is there a way to suspend an process belongs to shell A and foreground it in shell B? |
1,463,169,850,000 |
I have running processes on my server that get killed every night at midnight. It's at work, I'm not around when it happens and I don't have remote access.
The kill occurs very predicably at 23:59 every night. I know this because when I arrive the next day:
Processes are up until 23:59
Logs of the process show last m... |
It is common to rotate logs periodically, rotating them at midnight is common. Many applications will do this automatically.
For those that don't there are tools like logrotate that will do the rotation. Many programs are configured to reopen their logs when sent a HUP signal, and this is one of the techniques used... | What's the best strategy to catch mystery process? |
1,463,169,850,000 |
I'd like to set the PR_SET_CHILD_SUBREAPER process flag for the Bash process running my script, so that I can reap the tree of child processes that gets created (and can get killed in a non-orderly way) during its lifetime. Basically, I'd like Bash to call prctl(PR_SET_CHILD_SUBREAPER, 1, 0, 0, 0); on itself, but I ha... |
Since you mention it's fine with you, I feel obliged to introduce bash's equivalent...
ctypes.sh, a foreign function interface for bash
It's a shared object plugin for bash that is loaded with bash's enable -f mechanism:
enable [-a] [-dnps] [-f filename] [name ...]
The -f option means to load the new builtin command ... | How to set the CHILD_SUBREAPER flag for the Bash process running a script? |
1,463,169,850,000 |
If I have already started a job with GNU parallel in a similar fashion to:
$ cat jobs | parallel -j 70 "program {};"
is it possible, by e.g. some signal, to adjust the number of jobs of this parallel job? So that I could indicate to parallel that there should now be run at most 75 sub-jobs?
| ERROR: type should be string, got "\nhttps://www.gnu.org/software/parallel/parallel_tutorial.html#Number-of-simultaneous-jobs\n\nNumber of simultaneous jobs\n:\n--jobs can read from a file which is re-read when a job finishes:\necho 50% > my_jobs\n/usr/bin/time parallel -N0 --jobs my_jobs sleep 1 :::: num128 &\nsleep 1\necho 0 > my_jobs\nwait\n\nThe first second\nonly 50% of the CPU cores will run a job. Then 0 is put into my_jobs\nand then the rest of the jobs will be started in parallel.\n\nI highly recommend spending an hour walking through the tutorial. Your command line will love you for it.\n" | Is it possible to adjust number of sub-jobs for GNU parallel after invocation? |
1,463,169,850,000 |
When I had loads of firefox windows open and wanted to close them quickly I did
killall firefox
using killall from the psmisc package in Ubuntu.
Nothing happened.
I looked in the list of my processes and there were many lines of the form
alle_meije 55061 7662 0 01:16 ? 00:00:31 /usr/lib/firefox/firefox... |
killall firefox-bin works for me but then I use the official Firefox distribution.
As mentioned in the comments, pkill -f firefox should work as well.
-f The pattern is normally only matched against the process name. When -f is set, the full command line is used.
| killall firefox does not kill firefox |
1,429,872,458,000 |
I want to run a program so that it can only create new files and not overwrite existing ones.
Does something like this exist?
$ fsaccess --can read,write --not overwrite --command bash -c 'echo "stuff" > filetim; echo "Woohoo I did it"'
Now if filetim doesn't exist, then the command should run just fine, but if filet... |
If you want a process to be able to create new files but not overwrite pre-existing files, run it as a dedicated user and don't give this user write access anywhere except in some initially-empty directories. That way the program will not have the permission to overwrite any pre-existing file.
If you want to run a pro... | Process overwrite access restriction |
1,429,872,458,000 |
What is the difference between the two commands nice and renice to manage process priority?
|
nice launches a new command with a modified nice level (lower priority than it would have otherwise had, or higher priority if you have permission). You specify which command to launch by providing it as an argument to nice itself. nice actually execs that command, so nice itself doesn't terminate until the command do... | What is the difference between nice and renice? |
1,429,872,458,000 |
I can easily start 3 processes on 3 different terminals, and kill each one by pressing Ctrl+C. Now, is there any way to start all 3 processes at once, and then finish them equally easily? Ideas:
If I could start 3 processes in such a way that they would run on the same terminal, and Ctrl+C would kill all 3, that woul... |
Using bash's job control:
$ sleep 10m & sleep 11m & sleep 12m &
[1] 1821
[2] 1822
[3] 1823
$ jobs
[1] Running sleep 10m &
[2]- Running sleep 11m &
[3]+ Running sleep 12m &
$ kill %1 %2 %3
$ jobs
[1] Terminated: 15 sleep 10m
[2]- Terminated: 15 sl... | How do I start 3 processes on the same terminal, and then exit all 3 easily? |
1,429,872,458,000 |
Suppose if i have a situation in which some files need to be copied and it takes long time so
i would have to go for parallel processing of the file copy.
for example it may look like this
for i in ipaddresslist
do
cp x y & //running in back ground or some other process in background
done
wait //will cause till a... |
If some job needs to be started after some file has been copied, just make it part of the background job:
(cp this /there && start job that needs this in /there) &
(cp that /here && start job that needs that in /here) &
wait
(the last & is not necessary).
Now for more complex dependencies, you could use GNU make -j.
... | multiple background processes in a script |
1,429,872,458,000 |
I have a script which starts 3 terminal emulator windows:
#!/bin/sh
terminator --role='terminator-left' 2>/dev/null &
sleep 0.1
terminator --role='terminator-center' 2>/dev/null &
sleep 0.1
terminator --role='terminator-right' 2>/dev/null &
(I am using the --role option, so that I can automatically place the windows... |
Disclaimer :
I have had no opportunity to test my suggestion under openbox. I validated it under kde-plasma only,
My solution resorts on the wait shell internal command as documented in the POSIX Programmers manual. Some particular implementation could make the script simpler, using the -n option.
#!/bin/sh
ownkill(... | start multiple terminal windows in a "process group" so that remaining processes can be killed, if any one of the processes terminates |
1,429,872,458,000 |
As part of a provisioning script for CentOS 7 I am in need to have a one-liner that performs the following. Unfortunately, I have no clue how to achieve that.
If httpd is running then stop it
If httpd is not running then check if httpd is installed at all & start it
ideally the result is logged into /log/httpd/ AND /... |
In CentOS7, you have systemctl that will pretty much do most of this for you. If Apache is installed via the standard packages, this should work for you out-of-the-box:
echo -n $(date +"%s %F %T"): \
if systemctl is-active httpd; then \
systemctl stop httpd && echo "httpd stopped"; \
elif systemctl enable httpd; t... | One-Liner needed: Stop httpd if running already & Start httpd if not running |
1,429,872,458,000 |
How do I kill all processes with my username that were started within (past hour, past day) etc?
|
find your processes that are younger than an hour
extract the pids
kill the pids
process list:
$ ps -e -o pid,user,etimes,comm \
| awk -v me=$USER '$2 == me && $3 <= 3600 { print }'
Produces
661162 jaroslav 3006 chrome
667859 jaroslav 1711 chrome
669145 jaroslav 1471 chrome
671222 jaroslav 1016 ... | Kill all of my processes that were started within the past hour? |
1,429,872,458,000 |
Simple question. I'm trying to find the config file of pm2's logrotate module to edit it manually. Unfortunately this information is not provided in the Github repo's README. So where is this file?
Backstory: I accidentally added a config with the incorrect key using pm2 set pm2-logrotate:wrong-key. I don't want it to... |
Found it.
~/.pm2/module_conf.json
I believe this file stores configuration for all modules.
| Where on disk is the config file of pm2-logrotate module? |
1,429,872,458,000 |
I am trying my hand on Linux Signals. Where I have created a scenario mentioned below:
Initially block all SIGINT signals using sigprocmask().
If sender send SIGUSR1 signal then unblock SIGINT for rest of the process life.
However first step is successfully implemented but not able to unblock (or change) process ma... |
The kernel will restore the signal mask upon returning from a signal handler. This is specified by the standard:
When a thread's signal mask is changed in a signal-catching function
that is installed by sigaction(), the restoration of the signal mask
on return from the signal-catching function overrides... | Why below code is not able to unblock SIGINT signal |
1,429,872,458,000 |
I am trying to make an AV bug raspberry pi for a class.
I am using sox to record sound.
Which is working fine.
the issue is sox needs to be stopped by a control+C to stop and create the new file. If killall is sent from a different ssh session it will drop the other session and sox will not create the file.
listen.sh... |
Your pipeline
ps -aux | grep sox | kill 0
will not do what you want to do. This is because kill won't ever read the input from grep (the result from grep will also contain a lot of other things than just the PID of the sox process).
If you have pkill, just do
pkill sox
instead (use pkill -INT sox to send the same s... | Stopping a script process with a Control + C or something |
1,429,872,458,000 |
I have 5 processes running from one terminal (T1). All of them are running in background, but generate a lot of output.
Now from other terminal (T2), I want to kill one of them using KILL pid command. Then after 60 secs, I want to restart the same process (this will get a different pid obviously).
My script would look... |
So, you can have the output appear in the other terminal—though I doubt you really want to. To do so:
Find the tty of the terminal you'd like the output to go to; the easiest way is to run tty. This should print something like: /dev/pts/42.
In the other terminal, run: command > /dev/pts/42 &. If you want to do stderr... | How can I run a process in one terminal from another terminal |
1,429,872,458,000 |
I am trying to list the superusers processes currently running in my Kali distro. Using "pgrep -f sbin" I figured that would do the trick, however it only lists the PID numbers, not the actual name of the processes. How can I get it to do this?
Using "ps ef | grep "sbin" it returns a very unformatted list, is there a ... |
Solved it by adding the -l flag to pgrep:
pgrep -lf sbin
From man pgrep:
-l, --list-name
List the process name as well as the process ID. (pgrep only.)
| List superuser processes |
1,429,872,458,000 |
I am maintaining an application that currently consists of 4 processes that are dependant on each other in various ways. At the moment these processes are started, stopped and monitored via a rather "grown" bash script, which contains pearls like these:
# And another rather dirty way to identify the node Api
# process... |
How about runit, "a UNIX init scheme with service supervision"?
I think it matches your requirements, i.e.
"runit's service supervision resolves dependencies for service daemons designed to be run by a supervisor process automatically." (more)
checking a running service can be done via sv status service
there are al... | Host process for multiple processes? |
1,429,872,458,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,429,872,458,000 |
I created a CGROUP on my desktop called background. The purpose of this group is to run all my sysadmin scripts within its CPU limit of 10%. The group is created on every reboot with the following cronjob:
@reboot /usr/bin/cgcreate -t jerzy:jerzy -a jerzy:jerzy -g cpu:background && /usr/bin/cgset -r cpu.cfs_period_us=... |
Both commands are preparation commands exec-ing the following command while keeping the property they changed. So the order here won't matter as long as the changed properties don't have any side effect changing the other (it's fine for these two).
cgexec -> nice -> final executable
will move the following process ni... | Using cgroups and nice with respect to the same process - does the order matter? What is the correct syntax? |
1,429,872,458,000 |
I'm trying to do is create a new process, from within bash, like nothing ever happened, except my terminal is on the next line, where that process would normally steal my stdout...
Let's say I want to apt-get update right now, but i want to edit some configuration files instead of watching everything download, so I w... |
I believe you are looking for the setsid command which starts a program in a new session. So you can:
setsid apt-get update
And, if you want the apt-get update to be silent:
setsid apt-get update >/dev/null 2>&1
The good thing with setsid is that the process started this way will continue after the terminal closes.
| How can I run a program from bash ignoring its stdout so i can run more programs? [closed] |
1,429,872,458,000 |
I recently learned that I can use top with my keyboard to kill processes (k), show processes for a specific user only (u), etc. But I was wondering if there is a way of selecting processes from the menu without having to manually type their PID (e.g. using C-n and C-p to navigate the list would be ideal)
If top does... |
Maybe htop fits the bill. It is a nicer top.
Comparison between htop and top
In 'htop' you can scroll the list vertically and horizontally to see all processes and complete command lines.
In 'top' you are subject to a delay for each unassigned key you press (especially annoying when multi-key escape sequences are tr... | Task management tools with keyboard navigation that run in a terminal |
1,429,872,458,000 |
I'm looking for a way to run a process, which itself may spawn off more child / grandchild / etc. subprocesses. Then:
Be able to send a signal (e.g. TERM or KILL) to all descendants.
Be able to ensure that when the main process exits, all descendants are terminated (either by killing them or because we have waited fo... |
As it turns out, my testing methodology was off and PID namespaces seem to be the best tool for this job. BubbleWrap is one tool that allows creating them, and does get the job done:
args=(
bwrap
# Create PID namespace
--unshare-pid
# Make the filesystem namespace a straight map to the outer one
--... | Reliably run, wait for, and kill a tree of processes |
1,429,872,458,000 |
If I do:
sleep 1
versus
sleep 1 & wait $!
will there be any difference in terms of CPU usage for spawning a foreground process versus a background process? Or will the performance of both lines be exactly equal?
|
Yes.
On my system the first takes 3.0 ms and the second takes 3.3 ms CPU time.
In practice I would never worry about the 0.3 ms CPU time if you are sleeping a full second.
The 0.3 ms is probably caused by the extra fork that is needed to put sleep in the background. In other words: It is a one-time cost, not a 10% ext... | Is there a performance penalty for backgrounding a process? |
1,429,872,458,000 |
I want to understand the Process Control block of Mac OS and Linux. For Lionux it was pretty strightforward, there was a post here asking about the same thing and someone replied to go take a look at "task_struct" in <linux/sched.h>. However i am finding it more difficult to find the equivalent information for Mac OS,... |
I know nothing of Mac OS but… a couple about FreeBSD. Hope it will match.
You got it right looking at the task_struct in Linux because it's the basic unit of scheduling in Linux.
The basic unit of scheduling in FreeBSD is the thread.
Linux represents processes (and threads) by task_struct structures.
A single-threaded... | What is the equivalent of "task_struct" in linux's <linux/sched.h> for Mac OS? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.