Hot answers tagged

72

On my system it gets the uptime from /proc/uptime: $ strace -eopen uptime open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 open("/lib/libproc-3.2.8.so", O_RDONLY|O_CLOEXEC) = 3 open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 open("/proc/version", O_RDONLY) = 3 open("/sys/devices/system/cpu/online", O_RDONLY|O_CLOEXEC) = 3 ...


17

It depends on whether your application is a computational one (like this) or interactive. For a computational application, full utilisation of the CPU(s) is your goal, as that means that the result is ready sooner. Anything that causes that utilisation to go down is an opportunity for improvement (e.g. waiting on I/O). For an interactive application, any ...


15

Yes, it's man 7 signal which, among other things, includes the following table: Signal Value Action Comment ────────────────────────────────────────────────────────────────────── SIGHUP 1 Term Hangup detected on controlling terminal or death of controlling process SIGINT 2 ...


13

I doubt we'll ever be able to tell you where it went, but you should just be able to reinstall it using yum. yum reinstall man yum doesn't check to see if files exist when you run yum install, it just checks a database of which packages have been installed. If someone deletes all the files outside of the package manager, it won't know (you can get it to ...


11

The fastest way to remove them from that directory is to move them out of there, after that just remove them in the background: mkdir ../.tmp_to_remove mv -- * ../.tmp_to_remove rm -rf ../.tmp_to_remove & This assumes that your current directory is not the toplevel of some mounted partition (i.e. that ../.tmp_to_remove is on the same filesystem). The ...


10

As long as I know, uptime uses /proc/uptime to calculate system uptime. You can see it more clearly in the source code uptime.c FILE *fp; fp = fopen ("/proc/uptime", "r"); if (fp != NULL) { char buf[BUFSIZ]; char *b = fgets (buf, BUFSIZ, fp); if (b == buf) { char *end_ptr; double upsecs = c_strtod ...


8

If you want to prevent disk writes as much as possible, you can do this with Laptop Mode. One of the features of laptop mode is to allow a disk to spin down and to prevent the kernel from writing to it until memory gets full or until a timeout occurs (or until the disk needs to spin up in order to read data from it). See also the Arch Wiki. You'll presumably ...


7

On a standard UNIX system (based on the original sources *), uptime reads /var/adm/utmpx and checks for the last time of reboot entry. In other words: this is retrieving the date you also get with who -b and then computes the time since then. *) uptime is a link to the w program and was introduced by BSD around 1980.


7

One problem with rm -rf *, or its more correct equivalent rm -rf -- * is that the shell has first to list all the (non-hidden) files in the current directory, sort them and pass them to rm, which if the list of files in the current directory is big is going to add some unnecessary extra overhead, and could even fail if the list of file is too big. Normally, ...


7

rsync is surprisingly fast and simple. You have to create empty directory first, mkdir emptydir rsync -a --delete emptydir/ yourdirectory/ yourdirectory/ is the directory from where you want to remove the files.


6

In gcc –Werror this character: – is not a dash (-), but an en-dash. Replace that and/or use a different editor.


6

resize2fs probably didn't finish the job, but you can't tell because you missed the end of its output. You should not have gone ahead and executed lvreduce at that point. There is a very good chance that this corrupted part of your filesystem. Note that you cannot undo this operation by running lvextend and hoping that the lost bytes come back and that the ...


6

Use stat for that. In a GNU system: To get the username of the owner: stat -c '%U' file.txt To get the user ID (UID) of the owner: stat -c '%u' file.txt Assuming the file is file.txt. For FreeBSD and Mac OS X (thanks to @cas): For username: stat -f '%Su' file.txt For UID: stat -f '%u' file.txt


5

Yes, Linux's scheduler keeps track of where each thread was last scheduled, and favors keeping a thread on the same CPU if it can. You guessed the reason: migrating a thread from a CPU to another is more expensive than keeping it on the same CPU. There's even more to it: the scheduler knows about multiple levels of cache coherency, and tries not to migrate ...


4

free is provided by procps-ng; Debian 8 has version 3.3.9, which uses the old style with a separate line for buffers/cache, while Gentoo and presumably RHEL 7.x have version 3.3.10 or later which uses the new style. You can see the reasoning behind the change in the corresponding commit message. If you really want the old-style output you can run an older ...


4

The algorithm is described in much detail in the apt_preferences man page. In short, apt calculates a score for every version it knows about, based on command line options, configuration, and already installed packages. It then installs the version with the highest score. You can tweak things by specifying explicit scores for explicit sources, as described ...


4

The fastest is with rm -rf dirname. I used a snapshotted mountpoint of an ext3 filesystem on RedHat6.4 with 140520 files and 9699 directories. If rm -rf * is slow, it might be because your top-level directory entry has lots of files, and the shell is busy expanding *, which requires an additional readdir and sort. Go up a directory and do rm -rf dirname/. ...


4

Use Multiport for that iptables -A INPUT -p tcp --match multiport --dports 16000:65535 -j DROP also you may try iptables -A INPUT -p tcp --dport 16000:65535 -j DROP


4

What's probably happening is that the CPU goes into a more aggressive power-save mode. This causes the internal switch-mode voltage regulators to go into a pulse-skipping mode, moving the switching frequency down to the audible range. The noise comes from the inductors and capacitors, both being slightly microphonic (which also works in reverse; the emit ...


4

Because any directory is valid mountpoint The content of the latest mounted share will be listed AFAIK you cannot. The latest mount will be unmounted firstly # mkdir testmount # mount --bind /bin/ testmount/ # mount --bind /usr/bin/ testmount/ # mount |grep testmount /bin on /testmount type none (rw,bind) /usr/bin on /testmount type none ...


4

Creating a hardlink should probably be avoided, there's no need for one and a symlink is simpler and safer. Your other solutions are also fine though. You can create as script that calls the binary or you can add the directory to your PATH. The latter might be preferable if you expect to add other binaries in /opt as well. This is essentially a matter of ...


4

To organize the files by world: $ paste -d'\n' <(grep world1 file) <(grep world2 file) <(grep world3 file) <(grep world4 file) world1.com /randomkeygahjuh572/key639839 world2.com /randomkey788gauh72/key63whjk world3.com /randomkey788gauh72/key63whjk world4.com /randomkeyhghgdh778/key67567 world1.com ...


4

The -T option asks nodes (each hop) to insert a timestamp in the IP packets upon receiving a ping. It works by using the TS option of IP packets, specified by RFC791. ping -T requires one argument of tsonly, tsandaddr or tsprespec. tsonly returns only the timestamp. tsandaddr returns the timstamp and the address the packet was sent from. From the man ...


3

A bit dirty and there is probably a cleaner solution (maybe using SELinux or grsec) but you can hide a process by mounting an empty directory inside of /proc/<pid>. For example something like this : mount -o bind /empty/dir /proc/42 will prevent regular users from seeing process 42. They will however see that something is hidden as they will be ...


3

To debug problems with scheduling or applications performance on Linux, it is a good start to run task under perf stat. It reports statistics about the processor pipeline, its stalled cycles, or memory behaviour. Possible problems: Linux/Scheduler bug Intel HT is not keeping up with your threads Memory is not able to provide enough data for the program ...


3

On Debian or Ubuntu install stress-ng with apt-get install stress-ng. Then run: stress-ng -c 1 -l 50 playing with -c (number of CPUs) and -l (percentage load) parameters. For Fedora/RedHat/CentOS it seems you have to compile it (source repository is here) with the following procedure: wget ...


3

As for firewalls, I would be worried where they are placed, your Internet speeds, and how much rules you need on them. They can pretty much dictate the kind of hardware you will need. Be aware for more performance/higher speeds you may need better NIC cards. In the past I used top tier Intel Pro cards. About router/firewalls in ISP settings, I used to have ...


3

For python at least I recomend "Learn Python The Hard way", by Zed Shaw. Freely available online. Good stuff. Not sure if posting a link here is technically advertising... Here goes. Free Book


3

/dev/shm : It is nothing but implementation of traditional shared memory concept. It is an efficient means of passing data between programs. One program will create a memory portion, which other processes (if permitted) can access. This will result into speeding up things. /run/lock (formerly /var/lock) contains lock files, i.e. files indicating that a ...


3

Yes, unless you have a very recent kernel there is significant overhead when using loop devices on linux: data accessed through the loop device has to go through two filesystem layers, each doing its own caching so data ends up cached twice, wasting much memory (the infamous "double cache" issue) Aside from casual use better alternatives would be to use a ...



Only top voted, non community-wiki answers of a minimum length are eligible