Is it possible to tell whether a process/thread has the PF_NO_SETAFFINITY flag set? I'm running taskset on a series of process ids and some are throwing errors of the following form:
taskset: failed to set pid 30's affinity: Invalid argument
I believe this is because some processes have PF_NO_SETAFFINITY set (see Answer).
Thank you!
Yes - look at /proc/PID/stat's 'flag' field
<linux/sched.h
#define PF_NO_SETAFFINITY 0x04000000 /* Userland is not allowed to meddle with cpus_allowed */
Look here for details on using /proc:
http://man7.org/linux/man-pages/man5/proc.5.html
https://supportcenter.checkpoint.com/supportcenter/portal?eventSubmit_doGoviewsolutiondetails=&solutionid=sk65143
Example:
ps -eaf
www-data 30084 19962 0 07:09 ? 00:00:00 /usr/sbin/apache2 -k start
...
cat /proc/30084/stat
30084 (apache2) S 19962 19962 19962 0 -1 4194624 554 0 3 0 0 0 0 0 20 0 1 0 298837672 509616128 5510 18446744073709551615 1 1 0 0 0 0 0 16781312 201346799 0 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The flags are 4194624
Q: Do you mind specifying how you'd write a simple script that outputs
true/false based on whether you're allowed to set affinity?
A: I don't feel comfortable providing this without the opportunity to test, but you can try something like this...
flags=$(cut -f 9 -d ' ' /proc/30084/stat)
echo $(($flags & 0x40000000))
I've been doing some experimenting with PostGIS, and here's what I've noticed:
Suppose I have a table defined as follows:
CREATE TABLE IF NOT EXISTS geomtest (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
geom geometry(POLYGON, 4326) NOT NULL
);
And I add the following polygon:
SRID=4326;POLYGON((0 0,0 10,10 10,10 0,0 0))
If I query the geom column on its own, I get a Hex representation of the geometry. If I instead call ST_AsBinary(geom), I get a binary representation.
However, when I convert both the hex and binary representations to an array of bytes, the results I get are slightly different. The first comment is the result I get by converting the hex into binary, and the next is straight from ST_AsBinary()
//[1 3 0 0 32 230 16 0 0 1 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 36 64 0 0 0 0 0 0 36 64 0 0 0 0 0 0 36 64 0 0 0 0 0 0 36 64 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
//[1 3 0 0 0 1 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 36 64 0 0 0 0 0 0 36 64 0 0 0 0 0 0 36 64 0 0 0 0 0 0 36 64 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
As you can see, the first 4 bytes are identical; representing whether it's in big or little endian, and the type of geometry (3, in this case a Polygon). The rest of the bytes are the same too. The only difference is there are a few extra bytes added after the first 4.
I wondered if this had to do with representing the projection (SRID=4326), but I haven't found any evidence to that.
If someone could shed some light on this, I'd greatly appreciate it.
I didn't examine the bytes, but I am sure that the difference is the SRID that's not included in the WKB format.
Try st_asewkb instead.
I am trying to dump an old database back into my system, but a weird error occurs.
When I login to 'postgres' database (psql posgtgres) the files would load, and the data would be also inserted,
CREATE TABLE
ALTER TABLE
but when I login to the database I created(psql EXAMPLE), it says
syntax error near "1"
Here is the part of the file that fails when I'm logged in to 'EXAMPLE' database :
...f92, f93, f94) FROM stdin;
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Please note that it is exactly the same file, and it was not edited before I connected to 'EXAMPLE' database.
Thank you in advance
EDIT:
Here is the copy command that gives the error.
COPY mmm_a1_0912_vorskla_02c (shot_num, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27, f28, f29, f30, f31, f32, f33, f34, f35, f36, f37, f38, f39, f40, f41, f42, f43, f44, f45, f46, f47, f48, f49, f50, f51, f52, f53, f54, f55, f56, f57, f58, f59, f60, f61, f62, f63, f64, f65, f66, f67, f68, f69, f70, f71, f72, f73, f74, f75, f76, f77, f78, f79, f80, f81, f82, f83, f84, f85, f86, f87, f88, f89, f90, f91, f92, f93, f94) FROM stdin;
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
EDIT#2
FIXED:
Actually I initially assumed that every database you create will have a 'public' schema by default. My newly created database didn't. That was the issue.
I have the following input file
-------------------------------------
--- A-TKE spectrum (post-neutron)---
-------------------------------------
2-dim. array: (A = 73 To 162 Step 1) (E = 122 To 198 Step 1)
(The data are written according to the loop structure specified above.
The last loop is the inner-most one. Line breaks are not related to the data structure!
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 0 1 0 0 2 0 0 1 0 0 0 0
</A_TKE>
</Results>
This file is part of a bigger file, which contains more number block similar to the above one.
What I want to do is print in a seperate file the numbers that are within the file. As a first try, I thought "Let's print what is between two patters". The START pattern will be --- A-TKE spectrum (post-neutron)--- and the END pattern will </A_TKE>
I used
awk '/--- A-TKE spectrum (post-neutron)---/{flag=1;next}/</A_TKE>/{flag=0}flag{print}' input
To my surprise nothing is printed on the screen. Any idea on why is this happening?
I would also like to now if I can substitue next with a number that will correspond to the line that I want to print after the given pattern.
In perl (because whilst you start with awk, this is tagged as perl too):
perl -ne 'print if m/post-neutron/...m/A_TKE/' input
Which will do what your thingy was trying to.
It works by using the range operator - which is a perl construct which tests if the current file is between two markers.
And the fact that perl can run inline in the same way as awk or sed. -ne says "wrap this code in a while loop" that iterates a line at a time. (e.g. as sed/awk/grep do by default).
Otherwise ... it depends a little on what else is in your file. Because from the sample you gave - the only lines starting with a number are the ones you want. So:
perl -ne 'print if m/^\s*\d+\s*\d+/'
(Or combine the two tests:
perl -ne 'print if m/post-neutron/...m/A_TKE/ and m/^\s*\d+\s*\d+/'
Which will output anything between the two text markers that has number-space-number at the start of line.
Your awk script is almost there. I'd build it like this:
awk '
/<\/A_TKE>/ {exit}
flag && NF==50 {print}
/--- A-TKE spectrum .post-neutron.---/ {flag=1}
' input
You could optimize it of course, but just looking at the logic of it, the idea is that you need do no further processing once you hit your end marker .. and you only want to start printing AFTER your start marker.
Note that I've replaced the brackets in your start marker with dots, since brackets are interpreted as PART OF THE REGULAR EXPRESSION. I believe you may be considering these simple strings to search for, but they are regex.
Some working ideas
Awk can print between two matching lines with this simple command:
awk '/PATTERN1/,/PATTERN2/' file.txt
If you want more control over what happens when the lines are found, you can use the flag approach.
awk '/A-TKE/{f=1;for (i=0;i<7;i++){getline}}/A_TKE/{f=0}f' file.txt
Adjust i<7 to specify how many lines you would like to skip.
Also, in this particular case, you can exploit the fact that you have 50 fields of numbers, which is unlikely to occur anywhere else in the file. Thus, you could also get the numbers of interest out with:
awk 'NF>40' file.txt
NF is a special awk variable that stores the number of fields (columns) in the current record (line).
Why your approach does not work
Your approach does not work, because everything that is between // in awk is treated as a regular expression. In your case you have several - and () in the string, which are not escaped, and thus assume their special meaning and therefore the expression you typed never matches, thus the flag is never set to 1 and awk does not print a line.
Try this simple sed command
sed -n '/A-TKE/,/<\/A_TKE>/p' FileName
If you want to extract rows with just numbers
awk 'NF && !/[a-zA-Z\-]+/' input.file
will generate
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 1 0 0 0 1 0 0 2 0 0 1 0 0 0 0
with patterns and smart counters you can write it as
awk '/\/A_TKE/{exit}
f&&s&&s--{next}
f&&NF{print}
/A-TKE spectrum/{f=1;s=7}' input.file
fine tune patterns as you like.
I want to run a video in matlab but I got some problems while doing so. I tried to run the video while using 'load' and then 'implay'. But I got this problem. My movie file is a textfile which constains mostly of zeros, arranged diagonally.
When I load this file in matlab I get different values. Here a snippet:
0 0 0 0 0 0 0 0 0 0 0
0 0 -5 0 0 -5.00097609500000 0 0 0 0 0
0 0 -10 0 0 -10.0019423800000 0 0 0 0 0
0 0 -15 0 0 -15.0028988550000 0 0 0 0 0
0 0 -20 0 0 -20.0038455200000 0 0 0 0 0
0 0 -25 0 0 -25.0047823750000 0 0 0 0 0
0 0 -30 0 0 -30.0057094200000 0 0 0 0 0
0 0 -35 0 0 -35.0066266550000 0 0 0 0 0
0 0 -40 0 0 -40.0075340800000 0 0 0 0 0
0 0 -45 0 0 -45.0084316950000 0 0 0 0 0
I dont know why I get a mat.file with different values and why my movie does not run. I wanted to upload the original textfile but this not possible.
When I try to run I receive following message: There is not enough memory to open 'filename' in the Editor.
I hope you guys can help me!