Unix how do you block unix/linux `wall` messaging?
mesg n
From the man page
DESCRIPTION
Mesg controls the access to your terminal by others. It's typically used to allow or disallow other users to write to your terminal (see write(1)).
Edit:
This will not prevent root
from sending wall messages
Linux message to all terminals
Did you have a look at the wall command?
See http://linux.die.net/man/1/wall
You need privileges to do this, but here is described a workaround
How do I broadcast messages to all bash terminal in python using wall command with stdin?
Confusion about a implementation of the system function in Unix
Besides the child process ending, the waitpid
function could return early if it was interrupted by a signal. If that happens to be the case, the if
block won't be entered and waitpid
will be attempted again.
Without the loop, if waitpid
gets interrupted you end up in a state where the parent process doesn't wait for the child and you end up with a zombie process when the child does exit. That zombie won't be cleaned up until the parent process exits, at which point the init process becomes the parent and automatically waits for the zombies.
Is there really no asynchronous block I/O on Linux?
The real answer, which was indirectly pointed to by Peter Teoh, is based on io_setup() and io_submit().
Specifically, the "aio_" functions indicated by Peter are part of the glibc user-level emulation based on threads, which is not an efficient implementation.
The real answer is in:
io_submit(2)
io_setup(2)
io_cancel(2)
io_destroy(2)
io_getevents(2)
Note that the man page, dated 2012-08, says that this implementation has not yet matured to the point where it can replace the glibc user-space emulation:
http://man7.org/linux/man-pages/man7/aio.7.html
this implementation hasn't yet matured to the point where the POSIX
AIO implementation can be completely reimplemented using the kernel
system calls.
So, according to the latest kernel documentation I can find, Linux does not yet have a mature, kernel-based asynchronous I/O model. And, if I assume that the documented model is actually mature, it still doesn't support partial I/O in the sense of recv() vs read().
How do I disable the Press ENTER or type command to continue prompt in Vim?
Found out one workaround: Add an extra <CR>
to the map command.
map <F5> :wall!<CR>:!sbcl --load foo.cl<CR><CR>
What simple mechanism for synchronous Unix pooled processes?
There's definitely no need to write this tool yourself, there's several good choices.
make
make
can do this pretty easy, but it does rely extensively on files to drive the process. (If you want to run some operation on every input file that produces an output file, this might be awesome.) The -j
command line option will run the specified number of tasks and the -l
load-average command line option will specify a system load average that must be met before starting new tasks. (Which might be nice if you wanted to do some work "in the background". Don't forget about the nice(1)
command, which can also help here.)
So, a quick (and untested) Makefile
for image converting:
ALL=$(patsubst cimg%.jpg,thumb_cimg%.jpg,$(wildcard *.jpg))
.PHONY: all
all: $(ALL)
convert $< -resize 100x100 $@
If you run this with make
, it'll run one-at-a-time. If you run with make -j8
, it'll run eight separate jobs. If you run make -j
, it'll start hundreds. (When compiling source code, I find that twice-the-number-of-cores is an excellent starting point. That gives each processor something to do while waiting for disk IO requests. Different machines and different loads might work differently.)
xargs
xargs
provides the --max-procs
command line option. This is best if the parallel processes can be divided apart based on a single input stream with either ascii NUL
separated input commands or new-line separated input commands. (Well, the -d
option lets you pick something else, but these two are common and easy.) This gives you the benefit of using find(1)
's powerful file-selection syntax rather than writing funny expressions like the Makefile
example above, or lets your input be completely unrelated to files. (Consider if you had a program for factoring large composite numbers in prime factors -- making that task fit into make
would be awkward at best. xargs
could do it easily.)
The earlier example might look something like this:
find . -name '*jpg' -print0 | xargs -0 --max-procs 16 -I {} convert {} --resize 100x100 thumb_{}
parallel
The moreutils
package (available at least on Ubuntu) provides the parallel
command. It can run in two different ways: either running a specified command on different arguments, or running different commands in parallel. The previous example could look like this:
parallel -i -j 16 convert {} -resize 100x100 thumb_{} -- *.jpg
beanstalkd
The beanstalkd
program takes a completely different approach: it provides a message bus for you to submit requests to, and job servers block on jobs being entered, execute the jobs, and then return to waiting for a new job on the queue. If you want to write data back to the specific HTTP request that initiated the job, this might not be very convenient, as you have to provide that mechanism yourself (perhaps a different 'tube' on the beanstalkd
server), but if the end result is submitting data into a database, or email, or something similarly asynchronous, this might be the easiest to integrate into your existing application.
Linux/Unix command to determine if process is running?
While pidof
and pgrep
are great tools for determining what's running, they are both, unfortunately, unavailable on some operating systems. A definite fail safe would be to use the following: ps cax | grep command
The output on Gentoo Linux:
14484 ? S 0:00 apache2
14667 ? S 0:00 apache2
19620 ? Sl 0:00 apache2
21132 ? Ss 0:04 apache2
The output on OS X:
42582 ?? Z 0:00.00 (smbclient)
46529 ?? Z 0:00.00 (smbclient)
46539 ?? Z 0:00.00 (smbclient)
46547 ?? Z 0:00.00 (smbclient)
46586 ?? Z 0:00.00 (smbclient)
46594 ?? Z 0:00.00 (smbclient)
On both Linux and OS X, grep returns an exit code so it's easy to check if the process was found or not:
#!/bin/bash
ps cax | grep httpd > /dev/null
if [ $? -eq 0 ]; then
echo "Process is running."
else
echo "Process is not running."
fi
Furthermore, if you would like the list of PIDs, you could easily grep for those as well:
ps cax | grep httpd | grep -o '^[ ]*[0-9]*'
Whose output is the same on Linux and OS X:
3519 3521 3523 3524
The output of the following is an empty string, making this approach safe for processes that are not running:
echo ps cax | grep aasdfasdf | grep -o '^[ ]*[0-9]*'
This approach is suitable for writing a simple empty string test, then even iterating through the discovered PIDs.
#!/bin/bash
PROCESS=$1
PIDS=`ps cax | grep $PROCESS | grep -o '^[ ]*[0-9]*'`
if [ -z "$PIDS" ]; then
echo "Process not running." 1>&2
exit 1
else
for PID in $PIDS; do
echo $PID
done
fi
You can test it by saving it to a file (named "running") with execute permissions (chmod +x running) and executing it with a parameter: ./running "httpd"
#!/bin/bash
ps cax | grep httpd
if [ $? -eq 0 ]; then
echo "Process is running."
else
echo "Process is not running."
fi
WARNING!!!
Please keep in mind that you're simply parsing the output of ps ax
which means that, as seen in the Linux output, it is not simply matching on processes, but also the arguments passed to that program. I highly recommend being as specific as possible when using this method (e.g. ./running "mysql"
will also match 'mysqld' processes). I highly recommend using which
to check against a full path where possible.
References:
http://linux.about.com/od/commands/l/blcmdl1_ps.htm
http://linux.about.com/od/commands/l/blcmdl1_grep.htm
How to stop MinGW and MSYS from mangling path names given at the command line
I just discovered a neat trick to avoid MSYS/MinGW translating the paths for you.
If you use double-slash to start the path, then MSYS won't translate the path to DOS format. So in OP's example, the -rpath switch should be specified like this:
-Wl,-rpath=//usr/lib/myrpath
All Unix/Linux tools seem to handle such spurious slashes without any problem, so even though your binary's rpath will start with //usr/... I think the loader will do the right thing.
Related Topics
How to Run Multiple Programs in a Sequence
Use Bash Variable Within Slurm Sbatch Script
How to Inform Gcc to Not Use a Particular Register
Overhead of Supporting Floating Point Arithmetic Inside the Linux Kernel
How Provide Nested Mount of Overlayfs
How to Increase Openfabrics Memory Limit for Torque Jobs
In Bash How to Split a Column in Several Column of Fixed Dimension
Synchronize Linux System Clock to Windows Ntp Service
Shell Script: Hexadecimal Loop
Why Does Script Not Recognize File Extension
Run Shell Command and Don't Wait for Return
Bash Script Properties File Using '.' in Variable Name
How to Schedule a Cron Job to Run 4Th Week of the Year
Linux Script Start,Stop,Restart
How to Read Input from the Terminal Using /Dev/Stdin and Read.Csv()