I develop a CGI in bash/html.
With this CGI, I'm able to display some informations from csv files.
One of theses informations is the consumption in RAM and CPU of different FRAME.
To display these informations, I create this page :
#!/bin/bash
echo "Content-type: text/html"
echo ""
echo '
<html>
<head>
<meta http-equiv="Content-Type" content="test/html"; charset=UTF-8">
<title> CLF MONITORING </title>
<h1> FRAME monitoring <font size=3> [ Index ] </font> </h1>
<hr size="4" color="blue">
<style>
body{
background-color: #eff1f0;
}
</style>
</head>
<body>'
echo "<table>"
echo "<tr>"
echo "<td>"
echo "<PRE>"
echo "`./FRAME_SCRIPT.sh cccc.csv bbbb.csv`"
echo "</td>"
echo "</tr>"
echo "</PRE>"
echo "</table>"
echo '</body>'
'</html>'
My script " FRAME_SCRIPT.sh " display informations about FRAME from different csv files. Here the script
#!/bin/bash
OLDIFS=$IFS
IFS=','
for arg
do
echo -e "File : $arg "
echo "======================================================="
echo ""
while read FRAME RAM CPU1 CPU2
do
if [[ $FRAME != $PREV ]]
then
PREV=$FRAME
echo "FRAME : $FRAME"
echo -e "-----------------\n"
fi
echo -e "RAM : \t$RAM\n\
CPU 1 :\t$CPU1\n\
CPU 2 :\t$CPU2\n"
echo ""
done < "$arg"
done
I run it with the command :
./My_script.sh *.csv
The output is :
File : cccc.csv
=======================================================
FRAME : MIAIBB00
-----------------
RAM :
CPU 1 :
CPU 2 :
FRAME : MIAIBTST1
-----------------
RAM :
CPU 1 :
CPU 2 :
FRAME : MIAIBYC00
-----------------
RAM : 8
CPU 1 : 2.0
CPU 2 : 4
RAM : 5
CPU 1 : 0.1
CPU 2 : 1
RAM : 6
CPU 1 : 0.2
CPU 2 : 1
RAM : 0.25
CPU 1 : 0.2
CPU 2 : 1
RAM : 64
CPU 1 : 3.0
CPU 2 : 7
RAM : 80
CPU 1 : 20.0
CPU 2 : 20
RAM : 8
CPU 1 : 1.0
CPU 2 : 2
RAM : 4
CPU 1 : 1.0
CPU 2 : 2
RAM : 4
CPU 1 : 1.0
CPU 2 : 2
RAM : 0
CPU 1 : null
CPU 2 : 0
File : bbbb.csv
=======================================================
FRAME : MO1PPC02
-----------------
RAM : 12
CPU 1 : 0.3
CPU 2 : 2
RAM : 8
CPU 1 : 0.2
CPU 2 : 2
RAM : 15
CPU 1 : 0.8
CPU 2 : 2
RAM : 8
CPU 1 : 0.5
CPU 2 : 1
RAM : 36
CPU 1 : 2.0
CPU 2 : 4
RAM : 48
CPU 1 : 8.0
CPU 2 : 12
RAM : 8
CPU 1 : 0.2
CPU 2 : 2
RAM : 8
CPU 1 : 0.2
CPU 2 : 2
RAM : 31
CPU 1 : 2.0
CPU 2 : 8
But on my web page I would like to display the informations like that :
The idea is when everytime the pattern " File : XXXXX " appears, this patterns with his own informations is displayed in a new column, next to the previous patterns " File : XXXX ".
I think if we use the " File : " like the key pattern, it's possible. I can't use the name of the file because it's never the same one. Maybe it's possible to do this, but I don't know how...
In my exemple, I run my script in a directory with only 2 csv files, but in reality, I have a lot more csv files. So in this case, I use only 2 csv to be more clearly.
Do you have any idea to do this ?
Don't use shell loops to manipulate text (see why-is-using-a-shell-loop-to-process-text-considered-bad-practice).
If I were you I'd format the output as an HTML table rather than pre-formatted text but just follow the steps below to see one way to get the output you want:
$ cat ../tst.awk
BEGIN {
FS = ","
OFS = " : "
split("FRAME,RAM,CPU 1,CPU 2", titles)
}
FNR == 1 {
close(out)
out = "out" ++cnt ".txt"
print "File", FILENAME ORS "====================" > out
}
$1 != prev {
print "" ORS fmt(1) "\n--------------------\n" > out
prev = $1
}
{
for (i=2; i<=NF; i++) {
print fmt(i) > out
}
print "" > out
}
function fmt(fldNr) { return sprintf("%-8s%s", titles[fldNr] OFS, $fldNr) }
.
$ ls
bbbb.csv cccc.csv
.
$ tail -n +1 *.csv
==> bbbb.csv <==
MO1PPC02,12,0.3,2
MO1PPC02,8,0.2,2
MO1PPC02,15,0.8,2
MO1PPC02,8,0.5,1
MO1PPC02,36,2.0,4
MO1PPC02,48,8.0,12
MO1PPC02,8,0.2,2
MO1PPC02,8,0.2,2
MO1PPC02,31,2.0,8
==> cccc.csv <==
MIAIBB00,,,
MIAIBTST1,,,
MIAIBYC00,8,2.0,4
MIAIBYC00,5,0.1,1
MIAIBYC00,6,0.2,1
MIAIBYC00,0.25,0.2,1
MIAIBYC00,64,3.0,7
MIAIBYC00,80,20.0,20
MIAIBYC00,8,1.0,2
MIAIBYC00,4,1.0,2
MIAIBYC00,4,1.0,2
MIAIBYC00,0,null,0
.
$ awk -f ../tst.awk cccc.csv bbbb.csv
.
$ ls
bbbb.csv cccc.csv out1.txt out2.txt
.
$ tail -n +1 *.txt
==> out1.txt <==
File : cccc.csv
====================
FRAME : MIAIBB00
--------------------
RAM :
CPU 1 :
CPU 2 :
FRAME : MIAIBTST1
--------------------
RAM :
CPU 1 :
CPU 2 :
FRAME : MIAIBYC00
--------------------
RAM : 8
CPU 1 : 2.0
CPU 2 : 4
RAM : 5
CPU 1 : 0.1
CPU 2 : 1
RAM : 6
CPU 1 : 0.2
CPU 2 : 1
RAM : 0.25
CPU 1 : 0.2
CPU 2 : 1
RAM : 64
CPU 1 : 3.0
CPU 2 : 7
RAM : 80
CPU 1 : 20.0
CPU 2 : 20
RAM : 8
CPU 1 : 1.0
CPU 2 : 2
RAM : 4
CPU 1 : 1.0
CPU 2 : 2
RAM : 4
CPU 1 : 1.0
CPU 2 : 2
RAM : 0
CPU 1 : null
CPU 2 : 0
==> out2.txt <==
File : bbbb.csv
====================
FRAME : MO1PPC02
--------------------
RAM : 12
CPU 1 : 0.3
CPU 2 : 2
RAM : 8
CPU 1 : 0.2
CPU 2 : 2
RAM : 15
CPU 1 : 0.8
CPU 2 : 2
RAM : 8
CPU 1 : 0.5
CPU 2 : 1
RAM : 36
CPU 1 : 2.0
CPU 2 : 4
RAM : 48
CPU 1 : 8.0
CPU 2 : 12
RAM : 8
CPU 1 : 0.2
CPU 2 : 2
RAM : 8
CPU 1 : 0.2
CPU 2 : 2
RAM : 31
CPU 1 : 2.0
CPU 2 : 8
.
$ paste *.txt
File : cccc.csv File : bbbb.csv
==================== ====================
FRAME : MIAIBB00 FRAME : MO1PPC02
-------------------- --------------------
RAM : RAM : 12
CPU 1 : CPU 1 : 0.3
CPU 2 : CPU 2 : 2
RAM : 8
FRAME : MIAIBTST1 CPU 1 : 0.2
-------------------- CPU 2 : 2
RAM : RAM : 15
CPU 1 : CPU 1 : 0.8
CPU 2 : CPU 2 : 2
RAM : 8
FRAME : MIAIBYC00 CPU 1 : 0.5
-------------------- CPU 2 : 1
RAM : 8 RAM : 36
CPU 1 : 2.0 CPU 1 : 2.0
CPU 2 : 4 CPU 2 : 4
RAM : 5 RAM : 48
CPU 1 : 0.1 CPU 1 : 8.0
CPU 2 : 1 CPU 2 : 12
RAM : 6 RAM : 8
CPU 1 : 0.2 CPU 1 : 0.2
CPU 2 : 1 CPU 2 : 2
RAM : 0.25 RAM : 8
CPU 1 : 0.2 CPU 1 : 0.2
CPU 2 : 1 CPU 2 : 2
RAM : 64 RAM : 31
CPU 1 : 3.0 CPU 1 : 2.0
CPU 2 : 7 CPU 2 : 8
RAM : 80
CPU 1 : 20.0
CPU 2 : 20
RAM : 8
CPU 1 : 1.0
CPU 2 : 2
RAM : 4
CPU 1 : 1.0
CPU 2 : 2
RAM : 4
CPU 1 : 1.0
CPU 2 : 2
RAM : 0
CPU 1 : null
CPU 2 : 0
.
$ paste *.txt | column -L -s$'\t' -t
File : cccc.csv File : bbbb.csv
==================== ====================
FRAME : MIAIBB00 FRAME : MO1PPC02
-------------------- --------------------
RAM : RAM : 12
CPU 1 : CPU 1 : 0.3
CPU 2 : CPU 2 : 2
RAM : 8
FRAME : MIAIBTST1 CPU 1 : 0.2
-------------------- CPU 2 : 2
RAM : RAM : 15
CPU 1 : CPU 1 : 0.8
CPU 2 : CPU 2 : 2
RAM : 8
FRAME : MIAIBYC00 CPU 1 : 0.5
-------------------- CPU 2 : 1
RAM : 8 RAM : 36
CPU 1 : 2.0 CPU 1 : 2.0
CPU 2 : 4 CPU 2 : 4
RAM : 5 RAM : 48
CPU 1 : 0.1 CPU 1 : 8.0
CPU 2 : 1 CPU 2 : 12
RAM : 6 RAM : 8
CPU 1 : 0.2 CPU 1 : 0.2
CPU 2 : 1 CPU 2 : 2
RAM : 0.25 RAM : 8
CPU 1 : 0.2 CPU 1 : 0.2
CPU 2 : 1 CPU 2 : 2
RAM : 64 RAM : 31
CPU 1 : 3.0 CPU 1 : 2.0
CPU 2 : 7 CPU 2 : 8
RAM : 80
CPU 1 : 20.0
CPU 2 : 20
RAM : 8
CPU 1 : 1.0
CPU 2 : 2
RAM : 4
CPU 1 : 1.0
CPU 2 : 2
RAM : 4
CPU 1 : 1.0
CPU 2 : 2
RAM : 0
CPU 1 : null
CPU 2 : 0
Hello I am writing a code using pthread_cond_wait() and pthread_cond_broadcast(). The objective of my code is to trigger four threads at a time which should run in parallel.When I am passing signal to four threads using pthread_cond_broadcast all the four are getting triggered serially.The triggered time for the four threads are as given below.
HH : MM : SS : MS : uS
Thread 1 12 : 59 : 05 : 27 : 407
Thread 2 12 : 59 : 05 : 27 : 586
Thread 3 12 : 59 : 05 : 27 : 879
Thread 4 12 : 59 : 05 : 28 : 113
From the observation we can see that triggered time of four threads are varying so can anyone tell me what is the reason for that?
I am trying to understand the way system-calls are invoked on a Linux machine. For this, I ran a guest machine with a Linux 3.0.43 kernel on the QEMU emulator.
In order to know the system call numbers, I instrumented the interrupt function in qemu (do_interrupt_all() in target-i386/seg_helper.c --- not very important). Basically whenever I get an int 0x80 interrupt, I print the value in the EAX register. The output of the run gave the system call numbers. I expected the exec system call for the init process first. Then a fork and some `brk system calls. However, I am not sure if that is what I got. I am printing the first 100 system call numbers here. My guest is a 64-bit machine. Here is an online code exploration for my kernel.
: 11
: 45
: 33
: 192
: 33
: 5
: 197
: 192
: 6
: 33
: 5
: 3
: 197
: 192
: 192
: 192
: 6
: 192
: 243
: 125
: 125
: 125
: 91
: 122
: 45
: 45
: 197
: 5
: 5
: 5
: 5
: 221
: 141
: 141
: 6
: 5
: 5
: 5
: 5
: 5
: 197
: 192
: 3
: 3
: 6
: 91
: 5
: 197
: 192
: 3
: 3
: 6
: 91
: 5
: 197
: 192
: 3
: 3
: 6
: 91
: 5
: 197
: 192
: 3
: 3
: 6
: 91
: 5
: 197
: 192
: 3
: 3
: 6
: 91
: 5
: 197
: 192
: 3
: 3
: 6
: 91
: 5
: 5
: 197
: 192
: 3
: 3
: 6
: 91
: 5
: 197
: 192
: 3
: 3
: 6
: 91
: 5
: 197
Yes, it's what you got (Linux System Call Numbers, 64-bit Linux System Call Numbers):
11 : sys_exevce, or exec's system call
45 : sys_brk, the thing under malloc
33 : sys_access
192 : lgetxattr
And so on.
I want to ensure that all system threads in Linux run on core 0, leaving all the other cores to my application. I am using RHEL 6 and I have added the following lines at the top of /etc/rc.d/rc.sysinit:
taskset -p 0x01 1
taskset -p 0x01 2
taskset -p 0x01 $$
I still see a lot of threads/processes with PPID 2 running on cores other than 0. This indicates that kthreadd (the process with PID 2) spawns others before the above statements are executed. How can I ensure that all children of process 2 also run of core 0?
Edit: Here are, for example, the threads on core 4. Can any of these be moved away from core 4?
~> ps -L -eo pid,ppid,tid,nlwp,tty,comm,psr | grep 4$
PID PPID TID NLWP TT COMMAND PSR <-line added
15 2 15 1 ? migration/4 4
16 2 16 1 ? ksoftirqd/4 4
17 2 17 1 ? watchdog/4 4
31 2 31 1 ? events/4 4
46 2 46 1 ? kintegrityd/4 4
54 2 54 1 ? kblockd/4 4
65 2 65 1 ? ata/4 4
88 2 88 1 ? aio/4 4
96 2 96 1 ? crypto/4 4
420 2 420 1 ? ext4-dio-unwrit 4
879 2 879 1 ? kdmflush 4
926 2 926 1 ? ext4-dio-unwrit 4
935 2 935 1 ? ext4-dio-unwrit 4
1632 2 1632 1 ? rpciod/4 4
Some kernel threads were bound to their special (logic)CPU to do some work related that CPU, You can't migrate those kernel threads from their CPU. What you can do is migrating and pinning all the other tasks.
I guess this strange requirement is not your final purpose, and this(the title) is not the right approach to your purpose. If you provide your final purpose, guys in the SO can help you.
Are there an efficient algorithm to search and dump all common substrings (which length is 3 or longer) between 2 strings?
Example input:
Length : 0 5 10 15 20 25 30
String 1 : ABC-DEF-GHI-JKL-ABC-ABC-STU-MWX-Y
String 2 : ABC-JKL-MNO-ABC-DEF-PQR-DEF-ZWX-Y
Example output:
In string 1 2
---------------------------
ABC-DEF 0 12
ABC-DE 0 12
BC-DEF 1 13
:
-ABC- 15,19 11
-JKL- 11 3
-DEF- 3 15
-JKL 11 3
JKL- 12 4
-DEF 3 15,23
DEF- 4 16
WX-Y 29 29
ABC- 0,16,20 0,12
-ABC 15,19 11
DEF- 4 16,24
DEF 4 16,24
ABC 0,16,20 0,12
JKL 12 4
WX- 29 29
X-Y 30 30
-AB 15,19 11
BC- 1,17,21 1,13
-DE 3 15,23
EF- 5 17,25
-JK 11 3
KL- 13 5
:
In the example, "-D", "-M" is also a common substring but is not required, because it's length is only 2. (There might be some missing outputs in example because there are so many of them...)
You can find all common substrings using a data structure called a Generalized suffix tree
Libstree contains some example code for finding the longest common substring. That example code can be modified to obtain all common substrings.