date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,525,798,884,000 |
I am using another dns resolver, blocky and using it with systemd-resolved. blocky already has features like caching and prefetching. So I don't want systemd-resolved running a cache and messing with blocky's prefetching. But how do I disable the "cache" for systemd-resolved?
Config file:
/etc/systemd/resolved.conf.d... |
It is 'Cache', not cache. systemd configuration is case-sensitive.
| How do I disable the "cache" for systemd-resolved? |
1,520,009,155,000 |
I tried to block the .zip TLD on my laptop (running fedora 38) with bind.
Installing bind
Updating named.conf:
options {
listen-on port 53 { 127.0.0.1; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_s... |
I think I solved it?
If I’m not mistaken, the problem seems to be with systemd-resolve / resolvectl not persisting it’s settings for long...
If I change the file /etc/systemd/resolved.conf such that it contains
...
[Resolve]
DNS=127.0.0.1
...
And then reboot, it seems to do (finally) what it should.
I’d still like t... | How do I get BIND (DNS) to be authoritative about a tld for more than a minute |
1,520,009,155,000 |
How to configure a Debian-based build with systemd, such that when connected to my VPN provider via an OpenVPN client, the system uses the DNS servers of the VPN provider?
|
I went on quite a journey with this one, so I just wanted to capture my finding and a solution.
Apparently, the gold standard for configuring this in the past was a helper script called update-systemd-resolved but apparently, this has stopped working with recent versions of NetworkManager.
These are the steps I went t... | How to configure OpenVPN client to use different DNS servers when connected |
1,520,009,155,000 |
I'm on Mint 20.3 (based on Ubuntu 20.04) and I keep having this weird problem where my network is all working fine and then suddenly, apparently out of the blue, it stops working and I can't access any websites. It's not my browser because the same happens using curl.
I found a thread that mentioned using systemd-res... |
It comes from this part of the source code:
resolve/resolvectl.c
1843
1844 r = bus_map_all_properties(bus,
1845 "org.freedesktop.resolve1",
1846 "/org/freedesktop/resolve1",
1847 property_ma... | "Failed to get global data: No buffer space available" on running "systemd-resolve --status" |
1,520,009,155,000 |
I was reading about systemd-resolved and how it listens on 127.0.0.53 for DNS requests. What is the purpose of running this server and making queries to it when you could directly query a DNS server such as one from Google, Cloudflare, or your ISP instead?
|
Running a local resolver (in general, not just systemd-resolved) can provide a number of benefits; typically, the first one is caching, since most local resolvers will cache responses to queries. This means that repeated queries will be handled faster.
Other benefits can be derived from the fact that the resolver is l... | What is the purpose of running a local DNS proxy server like systemd-resolved? |
1,520,009,155,000 |
I have a really annoying & confusing issue about domain name resolution, focused only on apt/apt-get utility.
When I try apt update, it gives me (sorry in french)
root@myhostname:~# apt update
Err :1 http://ftp.igh.cnrs.fr/pub/os/linux/raspbian/raspbian buster InRelease
Erreur temporaire de résolution de « ftp.igh.c... |
While digging in this strange situation, I've had an inspiration from articles telling about permissions. On first reading, no relation with my problem.
Anyway, I've checked file permissions on /etc/resolv.conf
Everything looks OK, except one particular point : /etc/resolv.conf is a symbolik link to /opt/... path
Ev... | APT - temporary failure in name resolution error |
1,520,009,155,000 |
I have an box running Ubuntu 18.04.4. There are two LAN interfaces enp3s0 and eno1: the former is connected to a 3G modem on LAN network and the latter is connected to a satellite modem on another network. Network Manager takes care of setting priority to the interfaces through Connectivity Check setting in its config... |
In the systemd-resolved terminology, a domain prefixed by ~ in DNS Domain fields indicates "direct queries for this domain into system-wide default DNS server: don't use per-link DNS servers for this domain". The combination ~. is the same, but for the root DNS domain . which is the implied suffix of all DNS domains.
... | DNS server selection between two LAN interfaces |
1,520,009,155,000 |
I'm using Kubuntu 18.04. When I'm in the office network, everything works fine, but when I connect to any other network (wired of wifi) I don't get proper DNS names - the old ones are still in systemd-resolve --status output. When I add the proper DNS address via systemd-resolve --set-dns=10.0.0.1 --interface=eno1, t... |
The answer turned out to be brutal and simple. The DHCP client was superseding the DNS entries in /etc/dhcp/dhclient.conf via supersede domain-name-servers ...,...;. I have no idea why it was there, I must've forgot that I've set this a while back.
The command that saved me:
sudo find /etc -type f -print0 2>/dev/null ... | DNS is not applied with systemd-resolved [closed] |
1,520,009,155,000 |
UseDomains=
Takes a boolean argument, or the special value "route". When true, the domain name received from the DHCP server will be used as DNS
search domain over this link, similar to the effect of the Domains=
setting. If set to "route", the domain name received from the DHCP
server will be used for routing ... |
There is a justification posted in 2015.
https://www.mail-archive.com/[email protected]/msg31563.html
iiuc, the concern was that multi-level domain names (i.e. those with at least
one dot) could be spoofed by controlling the search suffix. But for
names with at least two levels glibc only uses the search lis... | Why does systemd-networkd consider UseDomains= (domain search list from DHCP) less safe than LLMNR? |
1,520,009,155,000 |
While working on some unit test code that basically sends raw Ethernet packets from one MACVLAN to another MACVLAN (virtual) network interface I noticed that most of the time the test code fails to receive any of the packets sent from the first to the second MACVLAN. Using Wireshark I could see that the packets leave ... |
It took some time to have the correct inspiration that maybe there was something about the MAC addresses, so I added this safeguard expectation that then immediately triggered:
mac2 := Successful(netlink.LinkByIndex(macvlan2.Attrs().Index)).
Attrs().HardwareAddr
// ... something going on here
mac2now := Successf... | systemd networkd and/or resolved blocking receiving (raw) packets on virtual network interface? |
1,520,009,155,000 |
Lately systemd-resolved fails to resolve most domains with the following error:
$ resolvectl query slashdot.org
slashdot.org: resolve call failed: 'slashdot.org' does not have any RR of the requested type
I have currently reduced my config to the following:
[Resolve]
DNS=1.1.1.1
$ resolvectl status
Global
... |
This was a bug in systemd which has since been fixed.
| resolvectl query fails: 'domain' does not have any RR of the requested type |
1,520,009,155,000 |
in networkd man page, the search domains are used to handle single-label names:
The domains without the prefix are called "search domains" and are first used as search suffixes for extending single-label host names (host names containing no dots) to become fully qualified domain names (FQDNs). If a single-label host n... |
A single-label name is only handled by LLMNR, if solved.
If not solved, each of the list of words in Domains=:
Domains=domainA.example domainB.example ~example
is added at the end of the single-label and an attempt to resolve it is done. If it gets resolved at any trial, that is the end, if not resolved, try with the... | do "search domain" in networkd configuration and LLMNR conflict? |
1,520,009,155,000 |
I'm connecting to a corporate VPN via network-manager-l2tp with a pre-shared key and user+pass. I'm getting a correct DNS server IP automatically, which resolves the companies URLs correctly.
However, public internet isn't resolved (I tested with www.google.com all the time), but this depends on the perspective: I can... |
You may be able to achieve split DNS (conditional forwarding) with the following configuration (assuming ppp0 is your VPN interface and enp6s0 your regular LAN):
resolvectl dns ppp0 corp.ip.add.ress
resolvectl domain ppp0 ~corp.domain.name
resolvectl default-route ppp0 false
resolvectl default-route enp6s0 true
This... | systemd-resolved+VPN: 2nd DNS server ignored (L2TP) |
1,520,009,155,000 |
How would one quarantine any systemd processes from ever using ANY network interface or resources at OS-level?
Overview
Minimalistically, I'd like to setup a Linux gateway. Simple NAT, forwarding home-based LAN gateway ... WITHOUT systemd or systemd-networkd accessing network-based interfaces.
Rationale
There is no n... |
At the risk of being downvoted, if you don't want systemd to access network interfaces, don't use systemd.
Over the years, we have seen the systemd-suite absorbing more and more functionality, and some of these require network access. As you said it yourself: it's an octopus. And the inter-dependencies of the differe... | How do you block network acceess to systemd? |
1,520,009,155,000 |
#!/usr/bin/env bash
echo "pgrep not finding systemd-resolved has bitten many times."
if [ -z $(pgrep systemd-resolved) ]; then
echo -e "systemd-resolved not found by pgrep, trying another way.\n";
ps aux | egrep -i '(DNS|HOST|DH|RESOLV|systemd-resolved)' | egrep -v 'grep -E';
fi;
systemd-resolved not found by... |
As explained in man pgrep,
The process name used for matching is limited to the 15 characters present in the output of /proc/pid/stat. Use the -f option to match against the complete command line, /proc/pid/cmdline.
“systemd-resolved” has 16 characters, so it falls foul of this limit. If you run pgrep -f... | Why does pgrep not find systemd-resolved? |
1,520,009,155,000 |
A new vulnerability has discovered on the systemd package called Evil DNS allowing the remote control of a linux machine. From the security-tracker.debian , the debian Stretch , Buster and Sid are vulnerable. ( Also affect a various Linux distro with Systemd)
System check:
On Debian Stretch , my systemd --version is s... |
As per the Ubuntu security notice, the issue only affects systemd-resolved (this can be confirmed by looking at the patch fixing the issue). So a system which isn’t running systemd-resolved isn’t exposed, and stopping systemd-resolved is sufficient to prevent the attack.
This is the reason why the Debian tracker menti... | How to understand and mitigate the Evil DNS remote attack under linux systems? |
1,520,009,155,000 |
Here's what my nslookup is doing:
ubuntu@ca:~$ time nslookup focal-250
Server: 127.0.0.53
Address: 127.0.0.53#53
Non-authoritative answer:
Name: focal-250.test
Address: 128.8.8.187
;; connection timed out; no servers could be reached
real 0m15.024s
user 0m0.005s
sys 0m0.018s
The first six lines... |
nslookup will query for both A and AAAA records, so if the A query returns immediately and the AAAA never returns, then nslookup will print an immediate response, then timeout.
Here's a table I made of how the dnsmasq server on 128.8.8.254 answered various types of queries:
dig @128.8.8.254 A focal-250 immedi... | Why would nslookup return a response, then timeout? |
1,520,009,155,000 |
I am working with an embedded linux Target (ARM) and have the following problem:
When /etc/resolv.conf is updated, while a process is running (e.g. C Program using gethostbyname()) the running process does not take care about the new nameserver entry until it is restarted.
The DNS entry has been made with systemd-reso... |
Try adding resolve to your /etc/nsswitch.conf before dns entry, so hosts line will look like:
hosts: files mymachines resolve [!UNAVAIL=return] dns myhostname
| Update of /etc/resolve.conf needs restart of application |
1,520,009,155,000 |
With my laptop running an arch-linux I can not access some websites when I am at home like for example:
https://www.wikipedia.org/
https://wiki.archlinux.org/
https://www.leo.org/
But I can access those websites from university as well as from my parents' place.
There are some websites that I can access from home l... |
I suggest you check file /etc/nsswitch.conf. It is name service switch configuration file. Param. host in this file shows you sources which systemd-resolved uses for getting host by name.
| Some web sites can not be reached [closed] |
1,520,009,155,000 |
The issue
Changing the DNS option in resolv.conf from the VM's gateway to 8.8.8.8 will result in no DNS resolution.
resolvectl query google.com succeeds if I set DNS to my gateway.
The set-up
/etc/resolv.conf is linked to stub-resolv.conf
systemd-networkd is configured as follows:
[Match]
Name=enp0s3
[Network]
Addr... |
Changing the /etc/resolv.conf link to /run/systemd/resolve/resolv.conf and listing the DNS in /etc/systemd/network/foo.network and in /etc/systemd/resolved.conf made it so that the global and NIC settings listed by resolvectl point to 8.8.8.8 and succesfully resolve.
| Bypassing DHCP DNS with systemd-resolved |
1,520,009,155,000 |
Maybe this is a dumb question but should Linux DNS resolver prefer primary DNS server over secondary and primary or is it free to use any of them?
I have a pretty standard ubuntu 20.04 LTS image with resolver configuration as per Microsoft recommendation
$ cat /etc/resolv.conf
options timeout:1 attempts:5
nameserver 1... |
It's a typical behavior of a DNS resolver that with multiple DNS servers defined, the servers are used round-robin. There is no concept of "primary" or "secondary" server in the resolver configuration - each of the configured servers is treated as equivalent.
| Should Linux resolver fail back to primary DNS server when it's available? |
1,303,517,105,000 |
I am getting output from a program that first produces one line that is a bunch of column headers, and then a bunch of lines of data. I want to cut various columns of this output and view it sorted according to various columns. Without the headers, the cutting and sorting is easily accomplished via the -k option to so... |
Stealing Andy's idea and making it a function so it's easier to use:
# print the header (the first line of input)
# and then run the specified command on the body (the rest of the input)
# use it in a pipeline, e.g. ps | body grep somepattern
body() {
IFS= read -r header
printf '%s\n' "$header"
"$@"
}
Now... | sort but keep header line at the top |
1,303,517,105,000 |
I have two text files. The first one has content:
Languages
Recursively enumerable
Regular
while the second one has content:
Minimal automaton
Turing machine
Finite
I want to combine them into one file column-wise. So I tried paste 1 2 and its output is:
Languages Minimal automaton
Recursively enumerable Turing m... |
You just need the column command, and tell it to use tabs to separate columns
paste file1 file2 | column -s $'\t' -t
To address the "empty cell" controversy, we just need the -n option to column:
$ paste <(echo foo; echo; echo barbarbar) <(seq 3) | column -s $'\t' -t
foo 1
2
barbarbar 3
$ paste <(echo foo; ... | combine text files column-wise |
1,303,517,105,000 |
On my PC I have to following routing table:
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 wlan0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
I don't understand how it is analyzed... |
The routing table is used in order of most specific to least specific.
However on linux it's a bit more complicated than you might expect. Firstly there is more than one routing table, and when which routing table is used is dependent on a number of rules.
To get the full picture:
$ ip rule show
0: from all lookup lo... | Which order is the route table analyzed in? |
1,303,517,105,000 |
I'm colorizing the header of a table formatted with column -ts $'\t'
Works well without color codes, but when I add color codes to the first line column doesn't properly align the output.
Without colored output it works as expected:
printf "1\t2\t3\nasdasdasdasdasdasdasd\tqwe\tqweqwe\n" | column -ts $'\t'
But when add... |
I imagine that column doesn't know that \e[7m is a v100 escape sequence that takes no space in the output. It seems to asssume character codes 0 to 037 octal take no space. You can get what you want by putting the initial escape sequence on a line of its own, then removing that newline from the output:
printf '\e[7m\n... | Issue with column command and color escape codes |
1,303,517,105,000 |
Is there an easy way to split comma-delimited lines of text into columns with some of the columns right-justified?
As a bonus, it would be nice to format numbers, but this probably isn't too hard with sed.
|
Awk and the %42s printf format comes to mind. Here's a simple script to get you started. Setting width[i] to a positive value in the BEGIN clause makes that column have the given width, left-aligned. If width[i] is negative, then column i is right-aligned and has the width -width[i]. This script doesn't handle wide fi... | Split a line into columns with some of the columns right-justified? |
1,303,517,105,000 |
I use column -t to format data for easy viewing in the shell, but there seems to be no option to specify column alignment (e.g. align to the right).
Any Bash one-liners to do it? I have arbitrary number of columns.
|
UPDATE: added a script (not a one liner, though) which allows you to choose which columns you want justified... It caters for Left (default) and Right (not Center).. As-is, it expects TAB delimited fields. You can change the column output seperator via $S.
RJustCol=(2 3 5) # Set columns to be right justified.
RJus... | Set alignment of numeric columns when columnating data |
1,303,517,105,000 |
I need to sort a CSV file, but the the header row (1st row) keeps getting sorted.
This is what I'm using:
cat data1.csv | sort -t"|" -k 1 -o data1.csv
Here's a sample line:
Name|Email|Country|Company|Phone
Brent Trujillo|[email protected]|Burkina Faso|Donec LLC|(612) 943-0167
|
This should work and output to data2.csv:
head -n 1 data1.csv > data2.csv &&
tail -n +2 data1.csv | sort -t "|" -k 1 >> data2.csv
| Sorting a CSV file, but not it's header [duplicate] |
1,303,517,105,000 |
I'm quite new at bash and I am trying to learn it by creating some small scripts.
I created a small script to look up the DNS entry for multiple domains at the same time. The domains are given as attributes.
COUNTER=0
DOMAINS=()
for domain in "$@"
do
WOUT_WWW=$(dig "$domain" +short)
if (( $(grep -c . <<<"$WOU... |
Using perl's Text::ASCIITable module (also supports multi-line cells):
print_table() {
perl -MText::ASCIITable -e '
$t = Text::ASCIITable->new({drawRowLine => 1});
while (defined($c = shift @ARGV) and $c ne "--") {
push @header, $c;
$cols++
}
$t->setCols(@header);
$rows = @ARGV / $col... | Bash output array in table |
1,303,517,105,000 |
I have some tables (table.txt) as follow:
YEAR MONTH DAY RES
1971 1 1 1345
1971 1 2 1265
1971 1 3 1167
The length of each time series goes from 1.1.1971 until 31.12.2099. Unfortunately, some time series are missing leap years and their values (e.g. year 1972 is a leap year so the month of February s... |
Maybe something like:
awk '
function isleap(y) {
return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)
}
$2 == 3 && $3 == 1 && isleap($1) && last_day != 29 {
print $1, 2, 29, (last_data + $4) / 2
}
{print; last_day = $3; last_data = $4}' file
| Leap year - extrapolating value |
1,303,517,105,000 |
I have some tables (table.txt) that have been wrongly built and present redundancey in the results, as follow:
YEAR MONTH DAY RES
1971 1 1 245
1971 1 2 587
...
1971 12 31 685
1971 1 1 245
1971 1 2 587
...
1971 12 31 685
1972 1 1 549
1972 1 2 746
...
Instead I would like to ... |
Here are two mutually exclusive sed loops:
sed -ne'p;/ 12 * 31 /!d;:n' -e'n;//!bn' <<""
YEAR MONTH DAY RES
1971 1 1 245
1971 1 2 587
...
1971 12 31 685
1971 1 1 245
1971 1 2 587
...
1971 12 31 685
1972 1 1 549
1972 1 2 746
...
1972 12 31 999
1972 1 1 933
1972 1 ... | Reformat tables |
1,303,517,105,000 |
I have several 'ascii' tables in a directory, some of them have numbers expressed in decimal and some others ones in floating point, as follow:
1 1 1423
1 2 1589
1 3 0.85e 5
1 4 0.89e 4
1 5 8796
...
Is there a way to convert all the value of the tables in decimal numbers?
I heard that using tr editor might be useful ... |
The sed script gets rid of the space after the 'e', and the awk script just prints out each field (multiplying $3 by 1 to "convert" it to a non-fp decimal number):
$ sed -e 's/e /e/g' file | awk '{print $1, $2, $3 * 1}'
1 1 1423
1 2 1589
1 3 85000
1 4 8900
1 5 8796
This assumes that the floating point numbers in the ... | Convert floating point numbers to decimal numbers |
1,303,517,105,000 |
I have a data file, which can have N rows, and each row is composed M elements separated by white space. Currently, I want to separate each row into several segments. In other words, assume the number of segments is 3; then the original file will be separated into 3 files, each of which has N rows and each row has M/... |
This caters for a varying number of fields in the same file, and the last segment being only partialy filled, ie less fields than specified (per segment).
Note though, that if the number of fields in a line results in fewer segments than specified, nothing is written to the output file for those shortfall segments. ... | separate a file into several small files according to columns |
1,303,517,105,000 |
I have a table in Linux :
A 0
A 0
A 0
B 0
B 1
B 0
B 1
B 0
I want to extract lines appeared consecutively for 3 times or more.
My expected output is :
A 0
Actually, 3 times or more is just a simplified example. The actual situation is I want to extract lines that appear consecutively for 30 times more.
Any idea?
Than... |
uniq -c file | awk '$1 >= 3 { print $2,$3 }'
The uniq -c will output each line together with a count of how many times that line occurs consecutively. For the given data, it will produce
3 A 0
1 B 0
1 B 1
1 B 0
1 B 1
1 B 0
The awk script will take this and output the last two fields if the first f... | Extracting lines appeared consecutively for 3 times or more in Linux |
1,303,517,105,000 |
So I don't want this:
echo "9"
9
Rather I need this, with e.g.: 4 spaces before it:
MAGICK "9"
9
So if I try it with 10:
MAGICK "10"
10
then it will just have 3 spaces before it. How can I format my output this way?
|
$ alias MAGICK="printf '%5s\n'"
$ MAGICK 10
10
| How can I right-justify variable length output? |
1,303,517,105,000 |
Considering a variable a describing temperature series for the city a. I have 9 directories (a1, a2, a3, a4, a5, a6, a7, a8, a9) each of them containing a table (respectively a1.txt, a2.txt, a3.txt, a4.txt, a5.txt, a6.txt, a7.txt, a8.txt, a9.txt).
I would like to move to another directory the table presenting the hig... |
This is not supposed to be a "write this program for me" site, so I am assuming that you have no idea where to start. So here's one way:
#!/bin/bash
highest=-999
for x in a[0-9]/a[0-9].txt;do
fourth="$(awk 'NR==1{print $4}' $x)"
if [ $highest -lt $fourth ];then
highest=$fourth
hifile=$x
fi
... | Move files/table following selection criteria |
1,303,517,105,000 |
I have a question concerning awk command in unix to merge multiple tables with a common value
Tab1
Geneid Chr Start End Strand Length Sample_1
ENSG00000278267 1 17369 17436 - 68 0
ENSG00000243485 1;1;1 29554;30267;30976 30039;30667;31109 +;+;+ 1021 0
Tab 2
Geneid Chr Start End Strand Len... |
awk '
{samples[$1] = samples[$1] OFS $NF}
END {
# print the header first
print "Geneid", samples["Geneid"]
delete samples["Geneid"]
# and then the rest of the data
for (geneid in samples) print geneid, samples[geneid]
}
' Tab*
Pipe the output into | column -t if y... | Awk for merging multiple files with common column |
1,303,517,105,000 |
I need a very quick and easy way to sort HTML tables. The table rows contain images that should stay with their appropriate row. I tried pasting my HTML into Libre Office calc, but the images are not pasted into rows, so sorting is not possible.
BTW, I do not want a sortable table. I want a sorted table. When done, I ... |
You can use Ex editor (part of Vi/Vim) as demonstrated in the following shell command:
$ ex +"g/<tr/;,/tr>/join" +"/<table\_.\{-}\zs<tr/;,/table>/sort /.\{-}<a href/" +%p -scq! table.html | html2text
[image of a]
a
[image of b]
b
[image of c]
c
[image of f]
f
Above example is using html2text command-line tool to dis... | Sorted HTML table |
1,303,517,105,000 |
On Ubuntu with kernel 4.16.7 I am writing a custom system call and, I want to set the NX bit of a specific Page Table Entry. So far I have this piece of code, where I am doing a page table walk to get the PTE I want and then try to set its NX bit:
pgd = pgd_offset(mm, addr);
if (pgd_none(*pgd) || pgd_bad(*pgd)){
p... |
So I found it by myself. The code is as follows:
struct vm_area_struct *vma;
unsigned long oldflags, newflags, pfn;
vma = find_extend_vma(mm, addr);
oldflags = vma->vm_flags;
newflags = oldflags &= ~VM_EXEC;
//...
//...
//...
if (pte_present(pte)){
printk("NX bit before: %d", pte_exec(pte));
pte = pte_modi... | Manually set NX bit of specific PTE |
1,303,517,105,000 |
I was wondering how to filter a table with several columns based on a specific value in each of the columns of interest.
I have this example here:
Chr1 16644 0 0 1 1
Chr1 16645 0 0 1 1
Chr1 16646 0 0 1 1
Chr1 16647 0 0 ... |
As @Devon mentioned in the comments: Use || instead of &&.
The reason is that you want show lines where at least one of the columns 3,4,5,6 is different then zero.
Here's another way to understand it. You're trying to remove lines where those columns are all zeros. Let's begin with the other way around: print all the ... | How to filter a table using awk |
1,303,517,105,000 |
I have several csv table as follow:
YEAR;MONTH;DAY;RES1;RES2
1971;1;1;1206.1;627
1971;1;2;1303.4;654.3
1971;1;3;1248.9;662
1971;1;4;1188.8;666.8
From this I would like to create a new column that concatenate the values of the columns MONTH and DAY. Therefore the output should look like that:
YEAR;MONTH;DAY;RES1;RES2;... |
Since you're happy for the header line to also be merged this is simple awk
awk -F';' -vOFS=';' '{ $(NF+1)=$2$3 ; print}'
Basically we add a new field $(NF+1) which consists of $2$3, which merges those fields. With OFS=';' the fields are output with ; separator.
| Adding column to a table by concatenating values from other columns |
1,303,517,105,000 |
I have a large GTF file, like below:
# ./stringtie -p 4 -G /home/humangenome_hg19/homo_gtf_file.gtf -o strAD1_as/transcripts.gtf -l strAD1 /home/software/star-2.5.2b/bin/Linux_x86_64/mapA1Aligned.sortedByCoord.out.bam
# StringTie version 1.3.2d
1 StringTi... |
Ideally, since the data is in GTF format, one should use a GTF parser to parse it. I currently have no such parser or parsing library installed so my solution is based solely on the data that you have provided in the question.
To extract the 9th column:
$ cut -f 9 data.gtf
gene_id "strAD1.1"; transcript_id "strAD1.1.... | Extracting quoted and labelled data from a given column |
1,303,517,105,000 |
I have different file for which I would like to change the header.
Currently the tables are as follow:
MONTH GFDL.ESM2M_ECOMAG GFDL.ESM2M_HYPE
1 3546.21855483871 2345.11127781945
I would like to change the . by some - but just for the header. Therefore I would like the following output:
MONTH GFDL-ESM2M_ECOMAG GFDL-E... |
sed '1s/\./-/g' file.txt
should do it for you
Why . ?
Because the . has a special meaning in sed. It is used used match any characcter. You need to strip the special meaning by escaping it ie \..
| Change header using sed or awk |
1,303,517,105,000 |
In a report file generated from Quartus, there are multiple "tables" like the following:
+---------------------+
; Section1 Title ;
+---------------------+
Miscellaneous text
+-----------------+
; Table1 Header ;
+--------+--------;
; Field1 ; Field2 ;
; Field3 ; Field4 ;
+--------+--------+
Table notes
+---... |
Perl's paragraph mode (-00) is good for this, it reads the input (stdin and/or file(s)) one paragraph at a time. A paragraph is a block of text extending until the next blank line - the paragraph boundary is one or more blank lines.
For example:
$ perl -00 -ne 'print if /Table1 Header/' quartus.rpt
+----------------... | How do I use sed to print only a specific "table" in a text report file? [duplicate] |
1,303,517,105,000 |
I have a bunch of input csv files (delimited with semi-colon ";" having the following format
YEAR;MONTH;DAY;RES1FILE1;RES2FILE1;RES3FILE1
1901;01;01;101;154;169
1901;01;02;146;174;136
The number of columns for each files is variable, meaning that some files could have 6 columns and some others 4.
I would like to past... |
I can think of two ways to approach this:
implement your own 'paste' that skips the first three fields of all but the first file - for example
awk -F\; '
FNR==NR {
a[FNR]=$0; next;
}
{
for (i=4;i<=NF;i++) a[FNR] = sprintf("%s;%s", a[FNR], $i);
}
END {
for (n=1;n<=FNR;n++) print a[n];
}' file*... | Paste different csv files |
1,303,517,105,000 |
This is a follow-up question to my previous question asked about 24 hours ago: Matching two main columns at the same time between files, and paste supplementary columns into the output file when those main columns match
G-Man solved that problem with a useful code, but I have a follow-up question. I already accepted t... |
Create the following files:
merge21:
BEGIN {
FS = "\t"
OFS = "\t"
}
NR==FNR { # file2
key = $2 "," $3
present[key] = 1
minor8[key] = $1
next
}
{ # file1
key = $1 "," $3
if (present[key]) print $1, $2, $3, $4, minor8[key... | Matching 2 main columns between files; and paste other columns into the output file when those main columns match. Keep row size of 1st file intact |
1,303,517,105,000 |
I have a table (ascii format with space delimiter), as follow:
1 1 1900 111
1 2 1900 121
1 3 1900 145
1 4 1900 1.45e 07
1 5 1900 5.21e 25
1 6 1900 152
I would like, that if there is a fifth column (obviously enclosing the value of the exponent) the value is replaced by 0. Therefore, considering this example, the desi... |
This should do the trick
awk '{if (NF>4){print $1, $2, $3 , "0" } else {print $0}}' INPUTFILE.txt
| Replace values in a table |
1,303,517,105,000 |
How can I resolve the problem of the tables going to the right. I just want it to be shown under 1.
Here's my script with START added. The alignment has gone wonky now:
while IFS="," read f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12
do
printf "START %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %5s" $f1 $f2 $f3 $f... |
You need to add a newline at the end of the printf statement, like so:
printf "START %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %10s %5s\n" $f1 $f2 $f3 $f4 $f5 $f6 $f7 $f8 $f9 $f10 $f11 $f12; # ifet the student id
(note the \n)
| Alignment when printing a series of records |
1,303,517,105,000 |
I have reports that are generated in the following tab-delimited format:
UNIT TC CC PC TCP FTX FRX
HOUSE 55 65 75 85 95 105
CAR 100 200 300 400 500 600
H2 5 10 15 20 25 30
C2 10 20 30 40 50 60
I need to change them to the following forma... |
Try:
$ awk 'BEGIN { FS="\t" } NR==1 { split($0,header,"\t") ; next } { for(i=2;i<=NF;i++) print $1,header[i],$i }' data
HOUSE TC 55
HOUSE CC 65
HOUSE PC 75
HOUSE TCP 85
HOUSE FTX 95
HOUSE FRX 105
CAR TC 100
CAR CC 200
CAR PC 300
CAR TCP 400
CAR FTX 500
CAR FRX 600
H2 TC 5
H2 CC 10
H2 PC 15
H2 TCP 20
H2 FTX 25
H2 FRX 3... | Move data row(s) to single column while retaining row header(s) |
1,303,517,105,000 |
I have a tab-delimited file like shown below, and would like to merge the rows based on matches in any of the columns. The number of columns are usually 2, but could vary in some cases and be 3.
input:
AMAZON NILE
ALASKA NILE
HELLO MY
MANGROVE AMAZON
MY NAME
IS NAME
desired output:
AMAZON NILE ALASKA MANGROVE
HELLO ... |
Using GNU awk
gawk '
{
grp = 0
# see if any of these words already have a group
for (i=1; i<=NF; i++) {
if (group[$i]) {
grp = group[$i]
break
}
}
# no words have been seen before: new group
if (!grp) {
... | Merge rows using common values in any column |
1,303,517,105,000 |
I have a table in which each entry looks something like,
coagulation factor VIII-associated 1 /// coagulation factor VIII-associated 2 /// coagulation factor VIII-associated 3
I would like to use cut -d/// -f2 myfile.txt, but I'm getting an error:
cut: bad delimiter
Same case when I use single quotes or double quot... |
If the delimiter is anything other than one fixed character, then cut is the wrong tool.
Use awk instead.
Consider this test file which has three fields:
$ cat file
one///two/2//two///three
To print the second field and only the second field:
$ awk -F/// '{print $2}' file
two/2//two
| How can I use a triple slash as a delimiter with cut? |
1,303,517,105,000 |
I have some tables were the numbers have too much digits; as follow:
MONTH A1 A2 A3 ......
1 1.54564468 2.48949 6.4984984 .....
Is there a way, using unix, to reformat the table in the following way:
MONTH A1 A2 A3 ...
1 1.54 2.49 6.50 ...
|
Assuming your table is actually a file of TAB-separated values:
awk -v OFS='\t' 'NR-1 { for(i=1; i<=NF; i++) $i = sprintf("%.2f", $i) } 1' <file.csv
Edit: Same thing with Perl:
perl -lape '$.-1 and $_ = join "\t", map { sprintf "%.2f", $_ } @F' file.csv
| Reformat table - Number of digits |
1,303,517,105,000 |
I have this table below, how can I calculate the sum of bytes for records in Nov only? for example below I want to find rows in Nov then sum the numbers in column4 relevant to Nov only? how I can do it?
1 arnold user 1933 Nov 7 13:05
2 megan user 10809 Nov 7 13:03
3 sam user 983 Apr 13 12:14
4 mark ... |
You can try awk as follows:
awk '$5 == "Nov" { sum += $4 }END { print sum }' file
80600
$5 represent the column relevant to months. $5 == "Nov" will filter the table for all records in November, then awk will sum the numbers in column $4
| How to calculate the sum of bytes in a column? |
1,303,517,105,000 |
I have some "CSV" data (actually using ; as a delimiter)
having a row for every day from 1971-01-01 through 2099-12-31
(a span of 2099−1971=128 years). The data are organized as follows:
YEAR;MONTH;DAY;RES1;RES2
1971;1;1;1206.1;627
1971;1;2;1303.4;654.3
1971;1;3;1248.9;662
1971;1;4;1188.8;666.8
1971;1;5;1055.2;667.8
1... |
If you want to average each day over all years, you could do something like
awk -F\; '
NR>1 {
sum1[$2";"$3]+=$4; sum2[$2";"$3]+=$5; n[$2";"$3]++;
}
END {
printf "MONTH;DAY;RES1;RES2\n";
for (i in n) printf "%s;%.1f;%.1f\n", i, sum1[i]/n[i], sum2[i]/n[i]
}' file.csv
Note that the output order isn... | Calculate average values for each day over multiple years |
1,303,517,105,000 |
I have some tables for which I need to replace a field that has a random position in each table.
For information, the table are semicolon separated fields and I would like to replace the field "datum" by "YEAR-MONTH-DAY".
So far, I have tried:
sed -i 's/datum/YEAR-MONTH-DAY/g' input > output
But it just outputs an em... |
As steeldriver astutely pointed out in the comments, you've told sed to -i edit the file in-place. As a result, sed will not provide any output, and so the > redirection will put that nothing into the output file.
Either keep the -i flag and accept that the input file will be updated in-place:
sed -i 's/datum/YEAR-MON... | Replace value in a table |
1,301,568,488,000 |
In ps xf
26395 pts/78 Ss 0:00 \_ bash
27016 pts/78 Sl+ 0:04 | \_ unicorn_rails master -c config/unicorn.rb
27042 pts/78 Sl+ 0:00 | \_ unicorn_rails worker[0] -c config/unicorn.rb
In htop, it shows up like:
W... |
By default, htop lists each thread of a process separately, while ps doesn't. To turn off the display of threads, press H, or use the "Setup / Display options" menu, "Hide userland threads". This puts the following line in your ~/.htoprc or ~/.config/htop/htoprc (you can alternatively put it there manually):
hide_user... | Why does `htop` show more process than `ps` |
1,301,568,488,000 |
I'm going through this book, Advanced Linux Programming by Mark Mitchell, Jeffrey Oldham, and Alex Samuel. It's from 2001, so a bit old. But I find it quite good anyhow.
However, I got to a point when it diverges from what my Linux produces in the shell output. On page 92 (116 in the viewer), the chapter 4.5 GNU/Linux... |
I think this part of the clone(2) man page may clear up the difference re. the PID:
CLONE_THREAD (since Linux 2.4.0-test8)
If CLONE_THREAD is set, the child is placed in the same thread
group as the calling process.
Thread groups were a feature added in Linux 2.4 to support the
... | Are threads implemented as processes on Linux? |
1,301,568,488,000 |
I am running a docker server on Arch Linux (kernel 4.3.3-2) with several containers. Since my last reboot, both the docker server and random programs within the containers crash with a message about not being able to create a thread, or (less often) to fork. The specific error message is different depending on the pro... |
The problem is caused by the TasksMax systemd attribute. It was introduced in systemd 228 and makes use of the cgroups pid subsystem, which was introduced in the linux kernel 4.3. A task limit of 512 is thus enabled in systemd if kernel 4.3 or newer is running. The feature is announced here and was introduced in this ... | Creating threads fails with “Resource temporarily unavailable” with 4.3 kernel |
1,301,568,488,000 |
Linux does not (yet) follow the POSIX.1 standard which says that a renice on a process affects "all system scope threads in the process", because according to the pthreads(7) doc "threads do not share a common nice value".
However, sometimes, it can be convenient to renice "everything" related to a given process (one ... |
Finding all PIDs to renice recursively
We need to get the PIDs of all processes ("normal" or "thread") which are descendant (children or in the thread group) of the to-be-niced process. This ought to be recursive (considering children's children).
Anton Leontiev answer's gives the hint to do so: all folder names in /p... | How to renice all threads (and children) of one process on Linux? |
1,301,568,488,000 |
I've read in many places that Linux creates a kernel thread for each user thread in a Java VM. (I see the term "kernel thread" used in two different ways:
a thread created to do core OS work and
a thread the OS is aware of and schedules to perform user work.
I am talking about the latter type.)
Is a kernel thread t... |
There is absolutely no difference between a thread and a process on Linux. If you look at clone(2) you will see a set of flags that determine what is shared, and what is not shared, between the threads.
Classic processes are just threads that share nothing; you can share what components you want under Linux.
This is ... | Are Linux kernel threads really kernel processes? |
1,301,568,488,000 |
$ ps -e -T | grep myp | grep -v grep
797 797 ? 00:00:00 myp
797 798 ? 00:00:00 myp
797 799 ? 00:00:00 myp
797 800 ? 00:00:00 myp
This shows the process myp with PID = 797 and four threads with different SPIDs.
How can I kill a particular thread of the process without killin... |
Threads are an integral part of the process and cannot be killed outside it. There is the pthread_kill function but it only applies in the context of the thread itself. From the docs at the link:
Note that pthread_kill() only causes
the signal to be handled in the
context of the given thread; the
signal actio... | How can I kill a particular thread of a process? |
1,301,568,488,000 |
Linux doesn't actually distinguish between processes and threads, and implements both as a data structure task_struct.
So what does Linux provide to some programs for them to tell threads of a process from its child processes? For example, Is there a way to see details of all the threads that a process has in Linux?
... |
From a task_struct perspective, a process’s threads have the same thread group leader (group_leader in task_struct), whereas child processes have a different thread group leader (each individual child process).
This information is exposed to user space via the /proc file system. You can trace parents and children by l... | How does Linux tell threads apart from child processes? |
1,301,568,488,000 |
I am trying to understand the Linux processes. I'm confused on the respective terms pid_max, ulimit -u and thread_max.
What exactly is the difference between these terms? Can someone clarify the differences?
|
Let us understand the difference between a process and a thread. As per this link,
The typical difference is that threads (of the same process) run in a
shared memory space, while processes run in separate memory spaces.
Now, we have the pid_max parameter which can be determined as below.
cat /proc/sys/kernel/pid... | Understanding the differences between pid_max, ulimit -u and thread_max |
1,301,568,488,000 |
I run iotop to check on programs that are heavy disk users, in case I need to decrease their priority. Usually this is good enough, but iotop only shows thread ID (TID), and sometimes I want to know process ID (PID) so I can find out more about which process is responsible.
Unfortunately, while ps can display TID (a.k... |
You can always do:
ps -eLo pid= -o tid= | awk '$2 == 792 {print $1}'
On Linux:
$ readlink -f /proc/*/task/792/../..
/proc/300
Or with zsh:
$ echo /proc/*/task/792(:h:h:t)
300
| Get PID from TID |
1,301,568,488,000 |
Following on from a problem described in "How is it that I can attach strace to a process that isn't in the output of ps?"
I'm trying to debug a process that hangs part way through.
By using strace -f on my parent process, I was able to determine that I have a bunch of threads that are just showing:
# strace -p 26334
... |
When you run strace the lines it's returning are system functions. In case it wasn't obvious epoll_wait() is a function that you can do a man epoll_wait to find out implementation details like so:
epoll_wait, epoll_pwait - wait for an I/O event on an epoll file descriptor
The description for epoll:
The epoll AP... | What information can I find out about an eventpoll on a running thread? |
1,301,568,488,000 |
A simple example. I'm running a process that serves http request using TCP sockets. It might A) calculate something which means CPU will be the bottleneck B) Send a large file which may cause the network to be the bottleneck or C) Complex database query with semi-random access causing a disk bottleneck
Should I try to... |
Linux:
The Linux kernel have a great implementation for the matter and have many features/settings intended to manage the ressources for the running process (over CPU governors, sysctl or cgroup), in such situation tuning those settings along with swap adjustment (if required) is recommended, basically you will be ada... | Should I attempt to 'balance' my threads or does linux do this? |
1,301,568,488,000 |
I ran the program pstree -p 31872 which printed the following output:
ruby(31872)─┬─{ruby}(31906)
└─{ruby}(32372)
The man page for pstree says:
Child threads of a process are found under the parent process and are
shown with the process name in curly braces, e.g.
icecast2---13*[{iceca... |
The mistake was to presume those numbers were PIDS, when in fact they are TIDS (thread IDs). See Linux function gettid(2). Reading up on clone(2) gives a lot of extra (and interesting) details.
| The program pstree and htop showing threads with unique PIDS. How is this possible? |
1,301,568,488,000 |
If I want to check if I got to the max of the nproc value should I do:
ps -ef | wc -l
Or
ps -efL | wc -l
Does nproc in limits.conf refers to number of processes or number of threads?
|
On Linux it refers to the number of threads. From setrlimit(2) (which is the system call used to set the limits):
RLIMIT_NPROC
The maximum number of processes (or, more precisely on Linux, threads) that can be created for the real user ID
of the calling process. Upon encountering this limit, fork(... | Does nproc in limits.conf refers to number of processes or number of threads? |
1,301,568,488,000 |
As far as I know in Linux kernel,
the structure task_struct represents threads i.e. light weight processes, but not processes.
processes are not represented by any structure, but by groups of threads sharing the same thread group id.
So is the following from Operating System Concepts correct?
Linux also provides ... |
Linux also provides the ability to create threads using the clone() system call. However, Linux does not distinguish between processes and threads. In fact, Linux uses the term task —rather than process or thread— when referring to a flow of control within a program.
We need to distinguish between the actual implemen... | Does Linux not distinguish between processes and threads? |
1,301,568,488,000 |
I know that external commands are run in the shell by creating a separate process, but what exactly happens when a built-in command is run in a shell?
Are they executed as a function, or does the shell create a new thread to execute them?
|
For your concrete example, there is a function cd_builtin, which is defined in builtins/cd.def (in the bash source code). It normally does a cd by calling that function. But it may fork first if you use it in a pipeline—for example, cd / | echo forks and calls cd_builtin in the child. You can also notice this by how t... | What exactly happens when a built-in command is run in a shell? |
1,301,568,488,000 |
I've been trying to enable context switch events on perf and use perf script's dump from perf.data to investigate thread blocked time.
So far the only two recording options that seem to be helpful are context switch and all the sched events.
Here's the command I'm running on perf:
perf record -g -a -F 999 -e cpu-clock... |
I know this question is pretty old (Feb 16) but here a response in case it helps someone else.
The problem is that you've entered the '-F 999' indicating that you want to sample the events at a frequency of 999 times a second. For 'trace' events, you don't generally want to do sampling. For instance, when I select sch... | Understanding Linux Perf sched-switch and context-switches |
1,301,568,488,000 |
In manpage of ps
tid TID the unique number representing a dispatchable
entity (alias lwp, spid). This value may also
appear as: a process ID (pid); a process group
ID (pgrp); a session ID for the session leader
... |
You need to task ps to show thread information; otherwise it only lists processes:
ps -eL -o pid,tid,comm | awk '$1 != $2'
will show all the threads, apart from each process’ main thread, i.e. entries in the process table where pid and tid are different. The significant option is -L: without that, ps will only list e... | Are tid and tgid always the same as pid in the output of ps? |
1,301,568,488,000 |
I've been reading a bit about threads and interrupts. And there is a sections which says that parallel programing using threads is simpler because we don't have to worry about interrupts.
However, what is the mechanism in which signals the release of the blocking system call if not an interrupt?
Example
I read i file ... |
Interrupts are handled by the operating system, threads (or processes, for that matter) aren't even aware of them.
In the scenario you paint:
Your thread issues a read() system call; the kernel gets the request, realizes that the thread won't do anything until data arrives (blocking call), so the thread is blocked.
K... | Are threads which are executing blocking system calls awoken by interrupts? |
1,301,568,488,000 |
Is a POSIX context switch well-defined? Is it the same thing as switching threads in C? Can the C compiler generate everything for a context switch or is assembly programming still needed for a routine that switches the threads or switches the "context"? Is there even defined what is meant by "context" - isn't it the ... |
POSIX uses the term context switch for at least two different purposes, without attempting to define it rigorously (or even providing a definition):
switching between threads, and
switching between processes
Rather, POSIX assumes you already know what the term means. For instance,
3.118 CPU Time (Execution Time)
Th... | Does POSIX define context switch? |
1,301,568,488,000 |
Do all threads of a specific process share the same status (D, R, S, ...) or may there be differences among these threads?
If so, where in /proc do I find information about the status of a certain thread? I am reading the process status from the /proc/<PID>/status files at the moment.
|
Different threads can certainly be in a different scheduler state at the same time. In fact, if they're all in the same state, that's a coincidence (except for stopped (Z), because that affects the whole process).
The subdirectory /proc/PID/task contains a subdirectory per thread of the process. The files in this dire... | Status of a threads vs. status of a process |
1,301,568,488,000 |
/proc/[pid]/ns/net contains a link to the inode representing the network namespace of the process with PID [pid]. Is there something similar for threads?
My use case is a multi-threaded application, where there's one main thread and a group of worker threads. The generic worker W creates a new network namespace N with... |
There is a file that associates a thread to its network namespace:
/proc/[PID]/task/[TID]/ns/net
where TID is the thread ID. This solved my issue.
| Is there a file that associates a thread to its network namespace? |
1,301,568,488,000 |
tgid and pid are the same concept for any process or for any lightweight process.
In /proc/${pid}/status, tgid and pid are distinct fields. Are tgid and pid ever different for a process or lightweight process?
Thanks.
|
When looking at /proc/${pid}/status, then the Tgid: and Pid: fields will always match, since they're the same for a process or for the main thread of a process.
The reason why there are two separate fields is that the same code is used to produce /proc/${pid}/task/${tid}/status, in which Tgid: and Pid: may differ from... | Are tgid and pid ever different for a process or lightweight process? |
1,301,568,488,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,301,568,488,000 |
I am increasing nproc limit for one of a development user account in my rhel6 system . After searching some rubust solution , I zerod at editing /etc/security/limits.conf with these two lines :
@dev_user hard nproc 4096
@dev_user soft nproc 4096
For some cases I have to deal wi... |
The settings specified in /etc/security/limits.conf are applied by pam_limits.so (man 8 pam_limits).
The pam stack is only involved during the creation of a new session (login). Thus you need to log out and back in for the settings to take effect.
| Increasing nproc limit for a non-root user . Only effective by restart |
1,301,568,488,000 |
Modern HDDs all are "Advanced Format" ones, e.g. by default they report a logical/physical sector size of 512/4096.
By default, most Linux formatting tools use a block size of 4096 bytes (at least that's the default on Debian/EXT4).
Until today, I thought that this was kind of optimized : Linux/EXT4 sends chunks of 4K... |
Following @Tomes advice, I'm trying to answer my own question, based on my comment exchange with @user10489.
Of course I am no expert on this matter, so don't hesitate to amend or correct my statements if needed.
But first, a clarification, because on a lot of websites people confuse block size and sector size :
A bl... | Are there any benefits in setting a HDD's logical sector size to 4Kn? |
1,301,568,488,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,301,568,488,000 |
I'm observing a multi threaded process in htop in tree view. If I were to strip it just to the problematic part, it looks somewhat like this:
CPU%
bin/process 100
`- thread1 70
`- thread2 0
The process all together is using 100% and one of the threads is using 70%. Where do... |
thread1 and thread2 are child threads spawned by the main process but the main process can still do work.
In your output of htop bin/process (and all child threads) are using 100% of cpu. 70% of the cpu is used by thread1 and 0% by thread2, the remaining (difference) is the main process that spawn/manages these child ... | 'htop' process and threads cpu usage? |
1,301,568,488,000 |
In linux or a library for linux, is there an equivalent to critical section in win32?
I am aware of Mutex, but it is not the same as critical section since a critical section uses user-mode spinlock and an event object internally, and it is must be faster than mutex.
|
If you want something coming from kernel space, then you might want to look at semaphores (sem_overview(7)). You can built higher level constructs from a semaphore, like "event", "condition", "mutex" ("critical sections"). There are the older and newer interfaces in C. Some higher level languages like Python and Pe... | critical section for linux |
1,301,568,488,000 |
I'm wondering about the "punishment" that occurs when a new thread is created.
From my understanding of clone(2), NPTL (New POSIX Thread Library), CFS (Completely Fair Scheduler), when a new thread is created it is seen as a new process because NPTL uses a 1:1 thread model.
From what I've read about the scheduler, w... |
From the link I provided about the Completely Fair Scheduler, we see that in kernel 2.6.24 has what is called group scheduling.
To quote from Chandandeep Singh Pabla:
For example, let's say there is a total of 25 runnable processes in the system. CFS tries to be fair by allocating 4% of the CPU to all of them. Howeve... | Thread process in linux |
1,301,568,488,000 |
I started 700+ threads from a single program And my /proc/[PID]/status file shows the following output.
VmPeak: 7228104 kB
VmSize: 7228104 kB
VmLck: 0 kB
VmHWM: 3456 kB
VmRSS: 3456 kB
VmData: 7222340 kB
VmStk: 88 kB
VmExe: 4 kB
VmLib: 1540 kB
VmPTE: 2864 kB
StaBrk: 15e8400... |
On some demand-paged virtual memory systems, the operating system refuses to allocate anonymous pages (i.e. pages containing data without a filesystem source such as runtime data, program stack etc.) unless there is sufficient swap space to swap out the pages in order to free up physical memory. This strict accounting... | Viewing virtual memory usage |
1,301,568,488,000 |
I understand the difference between /proc/sys/kernel/pid_max and /proc/sys/kernel/threads-max. There's a good explanation at the answer to
Understanding the differences between pid_max, ulimit -u and thread_max:
/proc/sys/kernel/pid_max has nothing to do with the maximum number
of processes that can be run at any giv... |
These settings don’t have the same effect:
threads-max limits the number of processes which can be instantiated simultaneously
pid_max limits the identifier assigned to processes
threads-max limits the amount of memory that can end up allocated to task_struct instances. pid_max determines when pids roll around (if e... | Why does Linux needs both pid_max and threads-max? |
1,301,568,488,000 |
The ps command can be done in terminal to view information about a process. For example,
#list processes
ps aux
#with executable paths
ps -ef
#path for a specific process
ps -p [pid]
However, if a process is large, it may be necessary to isolate what individual threads are doing. For example, kernel_task.
The command... |
The "-T" option for the ps command enables thread views.
# ps -T -p <pid>
For example, to list the threads for the following java process:
# ps -ef | grep 97947
deploy 97947 97942 1 00:51 ? 00:13:51 java
Alternatively, you can use top which can show a real-time view of individual threads. To enable thread v... | How do I do "ps" command on a thread? |
1,301,568,488,000 |
What does it mean when threads are time-sliced? Does that mean they work as interrupts, don't exit while routine is not finished? Or it executes one instruction from one thread then one instruction from second thread and so on?
|
Time-sliced threads are threads executed by a single CPU core without truly executing them at the same time (by switching between threads over and over again).
This is the opposite of simultaneous multithreading, when multiple CPU cores execute many threads.
Interrupts interrupt thread execution no matter of technolog... | Threads vs interrupts |
1,571,519,943,000 |
I know there is a one-line-per-thread view (-H), but the particular threads are not grouped by master process. In fact, I would be completely satisfied with the sole thread count per process (= how many sub-threads does some process create?).
|
The top man page describes the field you're looking for:
nTH -- Number of Threads
The number of threads associated with a process.
(number above would probably change depending on OS and top version).
Interactively, you can use the f (Fields Management) key, then move down to nTH, activate it with space, sele... | How do I display the thread / child process count of a process in top? |
1,571,519,943,000 |
I need to write a script to create and alert and get thread dumps if a string (Related string is found) in a log file - /tmp/area.log. I am able to do this in 2 separate scripts so far but would like combine them into one.
Script 1: create an alert
filelocation=$1
string=$2
count=$(cat $1 | grep -i "$2" | wc -l)
if ... |
It is very simple, hope you are asking to do thread dump when you find the string in the log.
So when you script 1 finds string in the log you need to run the thread dump script. To do so you need to include the thread dump script in the if [[ "$count" -ge 1 ]]; true block.
filelocation=$1
string=$2
count=$(cat $1 | ... | Look up a string in a log to set an alert and generate thread dumps |
1,571,519,943,000 |
when i do a ps -efT (where -T = Show threads, possibly with SPID column.), i see all the threads have the same PID, which is as expected.
myroot 24958 24958 7942 0 20:20 pts/12 00:00:00 java -jar myapp.jar
myroot 24958 24959 7942 0 20:20 pts/12 00:00:11 java -jar myapp.jar
myroot 24958 24960 7942 0 20:... |
With htop, you want the TGID column (add it through F2 > Columns). It is also available in top with the same name, but I don't know how to configure top.
Linux "processes" are really just thread groups (or task groups), and the "PID" column in top/htop actually shows the thread ID (task ID). The same clone(2) system c... | top shows different pid for threads of same process. How to fix it? |
1,571,519,943,000 |
How can I list information about a thread/LWP by ps?
Why can't I do that simply by:
$ ps 10173
PID TTY STAT TIME COMMAND
$ ps -L 10173
PID LWP TTY STAT TIME COMMAND
The best I can do
$ ps -eL | grep 10173
10172 10173 pts/8 00:00:00 java
It is a LWP because
$ ps -L 10172
PID LWP TTY ... |
If you want to see just that LWP process, ps -e -q 10172. If you want to see all the related threads, then you can do ps -eL -q 10172
So, for example, on my machine rsyslog has threads:
PID LWP TTY TIME CMD
22316 22316 ? 00:00:00 rsyslogd
22316 22318 ? 00:02:23 in:imjournal
22316 22319 ? ... | How can I list information about a thread/LWP by `ps`? |
1,571,519,943,000 |
How can I get the number of threads in the kernel at specific sampling rate? I need to measure the utilization of the system directly by myself.
|
ps -eL|wc -l
gives total number of lwp/thread count at any point of time
| Number of Threads in Kernel |
1,571,519,943,000 |
I read somewhere that Linux threads are really implemented as processes in the kernel since with today's hardware and on the Linux platform, the thread model is inefficient compared to the process model. If this is the case then why do we still use pthreads programming in our projects (other than for backward compatib... |
Judging by the question you pose you probably haven't seen problems where Threads provide an advantage over the standard processes.
There are problems like High-Frequency Trading for example where system becomes sensitive to the number of context switches in the system as well as switching from user to kernel mode and... | What is the advantage of using pthreads in Linux? |
1,571,519,943,000 |
POSIX thread (pthread) and OpenMP are both libraries for thread programming. But is it right that they are not native to Linux, i.e. they have to be installed by user later?
If yes, what are the native library or functions in Linux? Are they used to implement pthread and OpenMP?
To draw a parallel comparison to proce... |
What do you meant by “non-native”? There isn't a clear definition of “installed by default”, since each distribution has its own default set of installed packages and it's very easy to tune that set.
POSIX threads are part of GNU libc, which is a fundamental part of any non-embedded Linux systems (there are substitute... | Native and non-native support of thread/process programming in Linux? |
1,571,519,943,000 |
I am using this code in order to visualize how a spinlock would prevent context switching:
pthread_spinlock_t lock;
void pp()
{
pthread_spin_lock(&lock);
char d = 'D';
while(1) write(1, &d, 1);
}
void ppp()
{
char a = 'C';
while(1) write(1, &a, 1);
}
int main()
{
pthread... |
You need to try to acquire the lock in all threads which are supposed to be mutually exclusive:
void ppp()
{
pthread_spin_lock(&lock);
char a = 'C';
while(1) write(1, &a, 1);
}
Context-switching isn’t prevented by the lock’s existence, you prevent threads from making progress simultaneously by... | How does a spinlock prevents context switching? |
1,571,519,943,000 |
I have looked in several places such as here but none explain in detail the structs used for implementing the stack itself (the place where "tasks" (processes/threads) store their nested call information and such). Is it a linked list, or is it an array, or something else? I can't seem to find this information, but di... |
A stack is effectively an array -- it contains a bunch of words in contiguous memory, There is an important restriction -- it can only grow and shrink at one end (hence FILO -- First In Last Out) which is also LIFO.
Important difference from array too: Processor stack is logically split into Frames, and (unlike arrays... | What data structure is the stack using in Linux? |
1,571,519,943,000 |
I am studying the locking mechanisms in an OS and came across these POSIX functions:
pthread_cond_wait(pthread_cond_t *c, pthread_mutex_t *m);
pthread_cond_signal(pthread_cond_t *c);
I fully understand the idea behind the sleep/wake up here. But I am not sure how is this done in HW and how is it affecting scheduling.... |
A process/thread is woken up by inserting it in the queue of processes/threads to be scheduled. If you look at the source of signal, there is a user-space list of threads waiting on the conditional variable, and one of those gets woken with a futex system call. Checking an array of condition variables every tick would... | Could someone explain the sleep/wake dynamics in Linux? |
1,571,519,943,000 |
lscpu gives:
Thread(s) per core: 2
Core(s) per socket: 32
When running an intensive 32-threads process, why does htop show almost 100% CPU activity on #1-32, but very little activity on #33-64? Why aren't the process's 32 threads distributed evenly among CPUs #1-64?
|
In Linux there is a scheduler.
Some systems will push work to faster/cooler/more-efficient cores but the default behavior is an ordered stack.
The software you are running needs to take advantage of multiple cores for any benefit to be had, so it may be that your workload can only be split into 32 threads by your choi... | Distribution of threads among CPUs? |
1,571,519,943,000 |
In my tests, I always get the correct result so far with this:
[fabian@manjaro ~]$ sleep 10 & echo $!
[1] 302657
302657
But sleep and echo are getting executed simultaneously here, so I would expect that it can sometimes happen that echo executes before the value of $! is set properly. Can this happen? Why doesn't it... |
So
sleep 10 & echo $!
is two commands
sleep 10 &
echo $!
That they're on the same line doesn't change this.
So the shell will fork() a new process and put the process ID of the new process into $!. Then the new process will run the sleep and the other process will run the echo.
So you can be sure $! will always ho... | Will "$!" reliably return the correct ID with "&"? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.