Home Php C# Sql C C++ Javascript Python Java Go Android Git Linux Asp.net Django .net Node.js Ios Xcode Cocoa Iphone Mysql Tomcat Mongodb Bash Objective-c Scala Visual-studio Apache Elasticsearch Jar Eclipse Jquery Ruby-on-rails Ruby Rubygems Android-studio Spring Lua Sqlite Emacs Ubuntu Perl Docker Swift Amazon-web-services Svn Html Ajax Xml Java-ee Maven Intellij-idea Rvm Macos Unix Css Ipad Postgresql Css3 Json Windows-server Vue.js Typescript Oracle Hibernate Internet-explorer Github Tensorflow Laravel Symfony Redis Html5 Google-app-engine Nginx Firefox Sqlalchemy Lucene Erlang Flask Vim Solr Webview Facebook Zend-framework Virtualenv Nosql Ide Twitter Safari Flutter Bundle Phonegap Centos Sphinx Actionscript Tornado Register | Login | Edit Tags | New Questions | 繁体 | 简体


10 questions online user: 19

0
votes
answers
37 views
+10

一個線程中的崩潰如何影響其他線程。

2

我有一個2線程的程序。一個線程中的崩潰如何影響其他線程。

  • 線程1:在IOCTL調用(帶司機交互)
  • 線程2:做其他的東西在那裏SIGSEGV來了。

在這種情況下,Thread1完成ioctl調用的執行還是線程在執行內核代碼之間停止?

如果可能,請在Windows,Linux和Android上下文中提供答案(其中debuggerd附加到使用ptrace創建墓碑的進程)。

+0

請詳細說明您自己調查此過程的步驟。 –

沙发
0
1

對於Linux的回答:我假設進程將作爲處理SIGSEGV的線程2的一部分而終止。在Linux中,雖然系統調用代碼可能(例如,如果它處於所謂的可中斷等待中)通知進程終止並提前退出,但線程在它處於內核模式時通常不能終止。線程1一旦返回就會終止。

從開發的角度來看,我並不熟悉Android,但我的理解是,進程爲許多信號喚醒debuggerd守護進程,然後通過ptrace和dump來連接處理信號的進程過程狀態的各種位。我希望這可以在線程1從系統調用返回之前發生。

+0

感謝您花時間回答此問題。你可以提供任何引用_「線程不能正常終止,因爲它是在內核模式下」_ –

+0

如果正在執行的內核代碼顯式終止線程(例如,_exit系統調用)或另一個內核線程那麼做當然,線程可以在內核模式下終止。否則:我沒有很好的引用來提供,但看看kernel/exit.c和kernel/thread.c,特別是do_group_exit(),它是「被致命信號調用」的。這向組中的所有線程發送終止信號,並且信號在用戶模式下處理(例如,在完成系統調用之後)而不是處於內核模式。可中斷睡眠中的線程被喚醒。 – michaeljt

0
votes
answers
30 views
+10

程序錯誤:./program:錯誤而載入共享庫:LIB <xxx>的.so:無法打開共享對象文件:沒有這樣的文件或目錄

1

(我想使這個問題儘可能的通用,所以我會省略名稱圖書館,給了我標題問題。)程序錯誤:./program:錯誤而載入共享庫:LIB <xxx>的.so:無法打開共享對象文件:沒有這樣的文件或目錄

我有一個項目,併爲該項目,我需要一個圖書館xxx。因此,我下載了該庫,使用默認命令(./configure && make && make install && make clean)進行編譯 - 安裝過程已記錄 - 如果文檔中給出的示例用於查看是否正確設置了所有內容,則嘗試嘗試。我複製並粘貼在.c文件的代碼,並用下面的命令編譯它:

gcc -o program program.c -lxxx 

和GCC沒有報告任何錯誤。然而,當我運行程序時,會出現以下錯誤:

./program: error while loading shared libraries: lib<xxx>.so: cannot open shared object file: No such file or directory 

是到了我的心是用-static gcc的選項的第一個解決方案。它運行良好,程序正常運行。但我感到失望,因爲這意味着圖書館「嵌入」在程序中(抱歉在這裏錯誤的術語:我只是一個學生)。

於是,我找了在堆棧溢出的解決方案:這是我的發現:error while loading shared libraries: libnsd.so: cannot open shared object file: No such file or directory

圖書館是不同的,但使用命令

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH 

工作的罰款。實際上,libxxx.so位於/ usr/local/lib(僅通過使用ls /usr/local/lib | grep xxx)。另外,永久的解決方案線程顧名思義就是在文件/etc/ld.so.conf寫的目錄名稱:

sudo echo "/usr/local/lib" >> /etc/ld.so.conf 
sudo ldconfig 

這就是棘手的問題:ld.so.conf中文件包含以下行

include /etc/ld.so.conf.d/*.conf 

和目錄內/etc/ld.so.conf.d有一個名爲libc.conf包含行

/usr/local/lib 

我有點困惑,其中包括;如果它的工作方式與C#中的#include一樣,我應該在/etc/ld.so.conf文件中包含/ usr/local/lib。看起來並非如此。

+0

你安裝庫後運行'rehash'嗎? –

+0

該問題與C無關。 – alk

+0

[man ldconfig](https://linux.die.net/man/8/ldconfig) –

沙发
0
3

/etc/ld.so.conf僅被ldconfig讀取,其使用它來填充動態加載器高速緩存/etc/ld.so.cache。如果將庫裝入/usr/local/lib,並且/usr/local/lib包含在通過該機制的搜索路徑中,則只有在首先運行ldconfig時,它纔可以使用(不需要設置LD_LIBRARY_PATH)。

+0

嗨,對於遲到的回覆感到抱歉,並且非常感謝您回覆我的主題。我對ld.so.cache不瞭解......我會對此進行一些調查研究。無論如何,運行ldconfig已經解決了這個問題。所以,每當我在/ usr/local/lib中安裝一個動態加載庫時,我需要刷新緩存文件,不是嗎? – LuxGiammi

+0

是的,建議在系統範圍庫安裝後運行'ldconfig'。 –

0
votes
answers
36 views
+10

Kdbg中顯示的值是錯誤的 - NASM

0

如何測試k的值是否正確?Kdbg中顯示的值是錯誤的 - NASM

section .data 
    k dw 5 
    m dw 110 
    rez dw 0 
section .bss 
    tabela resq 3 
section .text 
global _start 
extern uslov 
_start: 
    mov qword [tabela], k 
    mov qword [tabela + 8], m 
    mov qword [tabela + 16], rez 

    mov rbx, tabela 
    call uslov 
mov rax, 60 
mov rdi, 0 
syscall 

當我嘗試檢查在工具KDbg m和蘇亞雷斯值的k,m,rez值是得很好,但k的值是完全不同的,現在剛開始我還以爲是隨機的,但它似乎艱難它將rez的值作爲一個8字節的數字而不是2個字節的數字讀取,並且還讀取了另外6個字節,並從m和rez中讀取所有的set 1,這是錯誤的,所以我怎樣才能正確顯示它?

截圖: enter image description here

+2

將表達式「(簡寫)k」添加到監視窗口中。 – Jester

沙发
0
3

我可以用你的源複製本(刪除未定義的引用uslov)當我編譯使用此命令行:

nasm -f elf64 test.asm -o test.o 
ld test.o -o test 

然後,在GDB我的確可以看到, k似乎有sizeof(k)==4

gdb ./test -ex 'tb _start' -ex r -ex 'p sizeof(k)' 
Reading symbols from ./test...done. 
Starting program: /tmp/test 

Temporary breakpoint 1, 0x00000000004000b0 in _start() 
$1 = 4 

釷是因爲最終的二進制文件只有關於k的唯一信息是它是數據區域中的符號。請參閱:

(gdb) ptype k 
type = <data variable, no debug info> 

調試器(工具KDbg使用GDB引擎蓋下),不知道它的大小,所以它只是猜測默認大小爲sizeof(int)。即使您通過-F dwarf -g選項在NASM中啓用調試信息,它仍然不會顯示任何實際的調試信息。

所以,你得到顯示大小合適的變量的唯一方法是手動指定它,如(short)k而不是k

+0

這不是一個bug,你(和OP)根本沒有包含該符號的任何*調試信息。 NASM不會將尺寸與基於'dd' /'dw' /'db'或其他任何其他指令/僞指令的標籤關聯起來。 (MASM甚至在'mov symbol,123'中暗示操作數大小,這與NASM不同)。 –

+0

如果你有'p&k',你會看到'$ 1 =( *)0x600104'。 GDB的默認解釋是'int'。 –

+0

@PeterCordes啊,我明白了。所以你的意思是它只是符號表中的符號,而不是DWARF數據中的符號?將不得不重新檢查。 – Ruslan

0
votes
answers
27 views
+10

通過啓動多個進程,而不是使用線程

2

縮放Ruby腳本我想增加一個腳本,不淨I/O(刮刀)的吞吐量。我不想在ruby中使用多線程(我使用默認的1.9.1解釋器),而是想要啓動多個進程。那麼,是否有一個系統可以做到這一點,我可以跟蹤何時完成重新啓動,以便隨時都可以運行X號碼。也有一些將運行不同的命令參數。我正在考慮編寫一個bash腳本,但是如果在linux上已經存在一個這樣的方法,這聽起來像是一個不好的想法。通過啓動多個進程,而不是使用線程

沙发
0
1

您可以嘗試叉http://ruby-doc.org/core/classes/Process.html#M003148

你可以得到回報的PID,看看這個過程又或無法運行。

如果你想管理的IO併發。我建議你使用EventMachine。

板凳
0
0

您可以

  1. 實現(或找到一個相當於創業板),一個線程池(ProcessPool,你的情況),或
  2. 準備所有的陣列,我們假設1000個待處理任務,拆分比如說10個100個任務(10個是你想要啓動的並行進程的數量),並啓動10個進程,其中每個進程立即接收100個任務進行處理。這樣,您不需要啓動1000個進程並控制其中不超過10個進程同時工作。
地板
0
2

我建議不要分叉,而應該使用EventMachine(如果您使用HTTP,則使用優秀的em-http-request)。管理多個進程可能有點少,甚至比處理多個線程更多,但相比之下,走向平坦的路徑要簡單得多。由於你主要想做網絡IO,主要是等待,所以我認爲一個平衡的方法可以擴展,或者比分叉或線程更好。最重要的是:它將需要更少的代碼,並且它會更具可讀性。

即使您決定爲每個任務運行單獨的進程,EventMachine也可以幫助您編寫管理子進程的代碼,例如使用EventMachine.popen

最後,如果您想在沒有EventMachine的情況下執行此操作,請閱讀文檔IO.popen,Open3.popenOpen4.popen。所有的功能或多或少都是相同的,但可以讓您訪問子流程的stdin,stdout,stderr(Open3,Open4)和pid(Open4)。

0
votes
answers
13 views
+10

無法在啓動時在Linux中啓動程序

-1

我無法在啓動設備時正常啓動程序。 我已經創建了一個腳本並將該腳本放入/etc/init.d/S77Hello.sh 在此腳本中,我啓動了該程序,該程序作爲其他程序的看門狗。 但啓動完成後,只有看門狗程序不運行應該由看門狗程序啓動的其他程序。無法在啓動時在Linux中啓動程序

有趣的是,當我使用以下命令啓動程序時: /etc/init.d/S77Hello.sh start 它以正常方式啓動所有其他程序。

S77Hello.sh

#!/bin/sh 
/usr/local/bin/mywatchdog 

任何有助於解決問題會有所幫助。

感謝, Yuvi

+0

您可以發佈'S77Hello.sh'文件的內容嗎? – 2013-02-22 18:46:49

+0

其簡單的腳本命令'/ usr/local/bin/mywatchdog'就是它。 – Yuvi 2013-02-22 18:51:19

+0

你的腳本在前臺運行你的程序。 '/ usr/local/bin/mywatchdog'程序是否足夠聰明,可以在啓動後進入後臺? – 2013-02-22 19:03:29

沙发
0
1

腳本在/etc/init.d不會自動在啓動時調用;你必須首先告訴你的init系統。如果您的發行版有/etc/init.d這可能通過update-rc.d完成。具體如下:

update-rc.d S77Hello.sh defaults 

查看相關手冊頁。如果你更喜歡GUI,rcconf提供了更友好的用戶界面,但你可能需要先安裝它。

然而,在你這樣做之前,修復你的init腳本;它缺乏重要的信息。如果您尚未閱讀,您可能需要閱讀this

最起碼,它需要是這個樣子:

#/bin/sh 
### BEGIN INIT INFO 
# Provides:   mywatchdog 
# Required-Start: $local_fs 
# Required-Stop:  $local_fs 
# Default-Start:  2 3 4 5 
# Default-Stop:  0 1 6 
# Short-Description: Start watchdog at boot time 
# Description:  Something something something 
### END INIT INFO 

case "$1" in 
    start) 
     /usr/local/bin/mywatchdog 
     echo $! >/var/run/mywatchdog.pid 
      echo "watchdog started." 
     ;; 
    stop) 
     if kill "$(cat /var/run/mywatchdog.pid)"; then 
      rm /var/run/mywatchdog.pid 
      echo "watchdog stopped." 
     else 
      exit 1 
     fi 
     ;; 
    *) 
     echo "Usage: $0 {start|stop}" 
     exit 1 
     ;; 
esac 

這是假設一個Debian-like系統在一定程度上,但由於您使用的是發行與ARM的sysvinit一個,我猜猜你在Raspberry Pi上使用Raspian。如果不是,請檢查現有init腳本在發行版中的工作方式。

14
votes
answers
18 views
+10

Undefined reference to pthread_create in Linux

I picked up the following demo off the web from https://computing.llnl.gov/tutorials/pthreads/

#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS     5

void *PrintHello(void *threadid)
{
   long tid;
   tid = (long)threadid;
   printf("Hello World! It's me, thread #%ld!
", tid);
   pthread_exit(NULL);
}

int main (int argc, char *argv[])
{
   pthread_t threads[NUM_THREADS];
   int rc;
   long t;
   for(t=0; t<NUM_THREADS; t++){
      printf("In main: creating thread %ld
", t);
      rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
      if (rc){
         printf("ERROR; return code from pthread_create() is %d
", rc);
         exit(-1);
      }
   }
   pthread_exit(NULL);
}

But when I compile it on my machine (running Ubuntu Linux 9.04) I get the following error:

corey@ubuntu:~/demo$ gcc -o term term.c
term.c: In function ‘main’:
term.c:23: warning: incompatible implicit declaration of built-in function ‘exit’
/tmp/cc8BMzwx.o: In function `main':
term.c:(.text+0x82): undefined reference to `pthread_create'
collect2: ld returned 1 exit status

This doesn't make any sense to me, because the header includes pthread.h, which should have the pthread_create function. Any ideas what's going wrong?

沙发
+40

You need to use the option -lpthread with gcc.

-pthread也適用於gcc - Sagar Jain 2014年7月15日10:16

錯誤的信息!-lpthread不是“選項”,它指定了一個庫。 - user1709175 2015年7月13日17:32

板凳
+40

If you are using cmake, you can use:

add_compile_options(-pthread)

Or

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
地板
+30

you need only Add "pthread" in proprieties=>C/C++ build=>GCC C++ Linker=>Libraries=> top part "Libraries(-l)". thats it

謝謝,這是有效的,我在CentOS中使用代碼塊,轉到設置 - >編譯器... - >鏈接器設置。然後在鏈接庫中添加“pthread” - Gus Arik 2016年4月28日8:26

4楼
+30

For Linux the correct command is:

gcc -o term term.c -lpthread

you have to put -lpthread just after the compile command,this command will tell to the compiler to execute program with pthread.h library.gcc -l links with a library file.Link -l with library name without the lib prefix.

5楼
0

In Anjuta, go to the Build menu, then Configure Project. In the Configure Options box, add:

LDFLAGS='-lpthread'

Hope it'll help somebody too...

6楼
0

Sometimes, if you use multiple library, check the library dependency. (e.g. -lpthread -lSDL... <==> ... -lSDL -lpthread)

7楼
0

check man page and you will get.

Compile and link with -pthread.

SYNOPSIS
       #include <pthread.h>

       int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
                          void *(*start_routine) (void *), void *arg);


       Compile and link with -pthread.
       ....
8楼
0

In Visual Studio 2019 specify -pthread in the property pages for the project under:

Linker -> Command Line -> Additional Options

Type in -pthread in the textbox.

54
votes
answers
34 views
+10

Repeat command automatically in Linux

Is it possible in linux command line to have a command repeat every n seconds.

For example, say I have an import running and i am doing

ls -l

to check the file size is increasing. I would like to have a command to have this automatically repeat.

沙发
+180

If the command contains some special characters such as pipes and quotes, the command needs to be padded with quotes. For example, to repeat ls -l | grep "txt", the watch command should be:

watch -n 5 'ls -l | grep "txt"'

我無法看到在管道表達上正常工作,但看完之後我就可以解決它:) - 吞噬極樂世界於2016年9月4日20:14

板凳
+130

Running commands periodically without cron is possible when we go with while.

As a command:

while true ; do command ; sleep 100 ; done &
[ ex: # while true;  do echo `date` ; sleep 2 ; done & ]

Example:

while true
do echo "Hello World"
sleep 100
done &

Do not forget the last & as it will put your loop in the background. But you need to find the process id with command "ps -ef | grep your_script" then you need to kill it. So kindly add the '&' when you running the script.

# ./while_check.sh &

Here is the same loop as a script. Create file "while_check.sh" and put this in it:

#!/bin/bash
while true; do 
    echo "Hello World" # Substitute this line for whatever command you want.
    sleep 100
done

Then run it by typing bash ./while_check.sh &

不是最後一個&,與沒有&最後編寫命令相同,但是使用&:bash ./while_check.sh&?調用腳本。 - ransh 2016年9月15日17:49

@ransh:我們可以運行腳本./while_check.sh所以我們可以立即獲取進程ID,當我們添加&in腳本並且只運行沒有&的腳本時,我們沒有得到任何進程ID但是它會運行背景,因為我編輯,如果我們需要停止腳本,我們需要ps命令來獲取進程ID。 - Ranjithkumar T 2016年9月22日5:29

如果您願意,可以修改腳本以回顯$!在每個後台進程啟動後 - 這是在後台啟動的最後一個子進程的PID。 - Jonathan Leffler 2016年9月22日5:49

echo`date`只是寫一個簡單的日期的窮人和略帶錯誤的方式。(該錯誤與缺少引用迴聲的參數有關。)另見無用的迴聲。 - Tripleee 1月12日20:29

地板
+70

watch is good but will clean the screen.

watch -n 1 'ps aux | grep php'
4楼
+60

If you want to avoid "drifting", meaning you want the command to execute every N seconds regardless of how long the command takes (assuming it takes less than N seconds), here's some bash that will repeat a command every 5 seconds with one-second accuracy (and will print out a warning if it can't keep up):

PERIOD=5

while [ 1 ]
do
    let lastup=`date +%s`
    # do command
    let diff=`date +%s`-$lastup
    if [ "$diff" -lt "$PERIOD" ]
    then
        sleep $(($PERIOD-$diff))
    elif [ "$diff" -gt "$PERIOD" ]
    then
        echo "Command took longer than iteration period of $PERIOD seconds!"
    fi
done

It may still drift a little since the sleep is only accurate to one second. You could improve this accuracy by creative use of the date command.

謝謝..但我有2個問題,1-在哪裡保存該代碼?換句話說,我應該在哪個路徑中放入包含該腳本的文件?這讓它自動運行?!2-如何在(#do命令)中包含php文件而不是在那裡輸入我的所有代碼? - Hossam於2002年2月1日9:46

我建議你研究一下bash腳本,這樣你就可以理解如何運行它們的基礎知識等等。 - 麥克特於18年5月18日0:47

5楼
+40

If you want to do something a specific number of times you can always do this:

repeat 300 do my first command here && sleep 1.5

這適用於csh但不適用於bash或sh。 - Keith Randall 2014年1月9日21:15

for bash do for x in {1..300}; 做命令|| break; sleep 1.5; 完成 - Jasen 2016年5月2日23:31

6楼
+40

You can run the following and filter the size only. If your file was called somefilename you can do the following

while :; do ls -lh | awk '/some*/{print $5}'; sleep 5; done

One of the many ideas.

7楼
+10

To minimize drift more easily, use:

while :; do sleep 1m & some-command; wait; done

there will still be a tiny amount of drift due to bash's time to run the loop structure and the sleep command to actually execute.

hint: ':' evals to 0 ie true.

沒理由-1。為你補償+1。 - FractalSpace 18年8月24日14:22

8楼
+10
watch -n 5 'ls -l 

Will Runls -l command after every 5s

Output :-

Every 5.0s: ls -l                                                                                                      Fri Nov 17 16:28:25 2017

total 169548
-rw-rw-r--  1 sachin sachin     4292 Oct 18 12:16 About_us_Admission.doc
-rw-rw-r--  1 sachin sachin      865 Oct 13 15:26 About_us_At_glance.doc
-rw-rw-r--  1 sachin sachin     1816 Oct 13 16:11 About_us_Principle.doc
-rw-rw-r--  1 sachin sachin     1775 Oct 13 15:59 About_us_Vission_mission.doc
-rw-rw-r--  1 sachin sachin     1970 Oct 13 16:41 Academic_Middle_school.doc
-rw-rw-r--  1 sachin sachin      772 Oct 16 16:07 academics_High_School.doc
-rw-rw-r--  1 sachin sachin      648 Oct 16 13:34 academics_pre_primary.doc
-rw-rw-r--  1 sachin sachin      708 Oct 16 13:39 academics_primary.doc
-rwxrwxr-x  1 sachin sachin     8816 Nov  1 12:10 a.out
-rw-rw-r--  1 sachin sachin    23956 Oct 23 18:14 Ass1.c++
-rw-rw-r--  1 sachin sachin      342 Oct 23 22:13 Ass2.doc
drwxrwxr-x  2 sachin sachin     4096 Oct 19 10:45 Backtracking
drwxrwxr-x  3 sachin sachin     4096 Sep 23 20:09 BeautifulSoup
drwxrwxr-x  2 sachin sachin     4096 Nov  2 00:18 CL_1
drwxrwxr-x  2 sachin sachin     4096 Oct 23 20:16 Code
drwxr-xr-x  2 sachin sachin     4096 Nov 15 12:05 Desktop
-rw-rw-r--  1 sachin sachin        0 Oct 13 23:12 doc
drwxr-xr-x  4 sachin sachin     4096 Nov  6 21:18 Documents
drwxr-xr-x 27 sachin sachin    12288 Nov 17 13:23 Downloads
-rw-r--r--  1 sachin sachin     8980 Sep 19 23:58 examples.desktop
0
votes
answers
16 views
+10

如何十六進制轉儲從4個十六進制數字組轉換爲2個十六進制數字組

0

如果我在下面的文本格式,這是在fortigate或的FortiMail如何十六進制轉儲從4個十六進制數字組轉換爲2個十六進制數字組

FortiMail # diag sniffer packet port1 'tcp port 443' 3 
interfaces=[port1] 
filters=[tcp port 443] 
10.651905 192.168.0.1.50242 -> 192.168.0.2.443: syn 761714898 
0x0000 0009 0f09 0001 0009 0f89 2914 0800 4500 ..........)...E. 
0x0010 003c 73d1 4000 4006 3bc6 d157 fede ac16 .<[email protected]@.;..W.... 
0x0020 0ed8 c442 01bb 2d66 d8d2 0000 0000 a002 ...B..-f........ 
0x0030 16d0 4f72 0000 0204 05b4 0402 080a 03ab ..Or............ 
0x0040 86bb 0000 0000 0103 0303 .......... 

如何CLI數據包捕獲數據包捕獲將其轉換爲此格式,以便能夠使用text2pcap將其轉換爲pcap。因此可以在wireshark中輕鬆打開。

FortiMail # diag sniffer packet port1 'tcp port 443' 3 
interfaces=[port1] 
filters=[tcp port 443] 
10.651905 192.168.0.1.50242 -> 192.168.0.2.443: syn 761714898 
0000 00 09 0f 09 00 01 00 09 0f 89 29 14 08 00 45 00 ..........)...E. 
0010 00 3c 73 d1 40 00 40 06 3b c6 d1 57 fe de ac 16 .<[email protected]@.;..W.... 
0020 0e d8 c4 42 01 bb 2d 66 d8 d2 00 00 00 00 a0 02 ...B..-f........ 
0030 16 d0 4f 72 00 00 02 04 05 b4 04 02 08 0a 03 ab ..Or............ 
0040 86 bb 00 00 00 00 01 03 03 03 .......... 
+0

您知道初始格式,所需的格式,那麼問題是什麼?您可以使用最喜歡的編程語言編寫自己的工具,或者使用支持正則表達式的文本編輯器來進行智能文本調整。或者使用帶有宏支持的文本編輯器在多行上應用相同的操作。 –

沙发
0
0

一個非常類似的問題被提出和回答的老Wireshark的詢問Q &站點。 Here「SA鏈接到我的回答這個問題張貼逐字下面爲了方便:


是的,你可以用text2pcap將其轉換爲一個PCAP文件,但你首先需要將數據按摩到的格式text2pcap接受,因爲描述的格式目前不支持text2pcap

因此,首先,你可以將數據通過Kurt Knochner的perl腳本轉換成合適的格式,給出的答案this問題,這裏複製的方便:

#!/usr/bin/perl 

$| = 1; 

my $regexp_time = '(dd:dd:dd.d+)'; 
my $regexp_hex = '(0xd+:s+)([0-9a-f ]+)+ '; 

while (<STDIN>) { 

    my $input = $_; 

    if ($input =~ /^$regexp_time/) { 
     print "$1
"; 
    } 

    if ($input =~ /$regexp_hex/) { 
     my $counter = $1; 
     my $line = $2; 

     $line =~ s/ //g; 
     $counter =~ s/(0x|:)//g; 

     print $counter . join(' ', ($line =~ m/../g)) . "
"; 
    } 
} 

假設tcpdump輸出被保存在一個名爲,tcpdump.txt文件,Kurt的Perl腳本保存爲convert.pl,運行:

cat tcpdump.txt | convert.pl > tcpdump_converted.txt 

一旦這樣做了,在轉換後的文件運行text2pcap

text2pcap -l 101 tcpdump_converted.txt tcpdump_converted.pcap 

請注意,這裏我指定「原始IP」封裝。有關鏈接類型,請參閱http://www.tcpdump.org/linktypes.html


我意識到不是從tcpdump產生的輸出,因此腳本可能無法正常工作究竟爲你的情況,但它不應該太困難定製以滿足您的需求如果它沒有做到你需要它開箱即用。

板凳
0
0

我解決了2 VIM問題替換命令

這樣一來取代所有4位十六進制爲2位十六進制

%s/s([0-9a-f]{2})([0-9a-f]{2})/ 1 2 /g 

而這一次刪除從行的開頭0X

%s/^0x// 

然後運行:

text2pcap in-mod.txt out.pcap 
145
votes
answers
54 views
+10

What are good Linux/Unix books for an advancing user? [closed]

Are there any good books for a relatively new but not totally new *nix user to get a bit more in depth knowledge (so no "Linux for dummies")? For the most part, I'm not looking for something to read through from start to finish. Rather, I'd rather have something that I can pick up and read in chunks when I need to know how to do something or whenever I have one of those "how do I do that again?" moments. Some areas that I'd like to see are:

  • command line administration
  • bash scripting
  • programming (although I'd like something that isn't just relevant for C programmers)

I'd like this to be as platform-independent as possible (meaning it has info that's relevant for any linux distro as well as BSD, Solaris, OS X, etc), but the unix systems that I use the most are OS X and Debian/Ubuntu. So if I would benefit the most from having a more platform-dependent book, those are the platforms to target.

If I can get all this in one book, great, but I'd rather have a bit more in-depth material than coverage of everything. So if there are any books that cover just one of these areas, post it. Hell, post it even if it's not relevant to any of those areas and you think it's something that a person in my position should know about.

up vote 62 down vote accepted favorite
沙发
+620
+50

I've wiki'd this post - could those with sufficient rep add in items to it.

System administration, general usage books

Programming:

Specific tools (e.g. Sendmail)

Various of the books from O'Reilly and other publishers cover specific topics. Some of the key ones are:

Some of these books have been in print for quite a while and are still relevant. Consequently they are also often available secondhand at much less than list price. Amazon marketplace is a good place to look for such items. It's quite a good way to do a shotgun approach to topics like this for not much money.

As an example, in New Zealand technical books are usurously expensive due to a weak kiwi peso (as the $NZ is affectionately known in expat circles) and a tortuously long supply chain. You could spend 20% of a week's after-tax pay for a starting graduate on a single book. When I was living there just out of university I used this type of market a lot, often buying books for 1/4 of their list price - including the cost of shipping to New Zealand. If you're not living in a location with tier-1 incomes I recommend this.

E-Books and on-line resources (thanks to israkir for reminding me):

  • The Linux Documentation project (www.tldp.org), has many specific topic guides known as HowTos that also often concern third party OSS tools and will be relevant to other Unix variants. It also has a series of FAQ's and guides.

  • Unix Guru's Universe is a collection of unix resources with a somewhat more old-school flavour.

  • Google. There are many, many unix and linux resources on the web. Search strings like unix commands or learn unix will turn up any amount of online resources.

  • Safari. This is a subscription service, but you can search the texts of quite a large number of books. I can recommend this as I've used it. They also do site licences for corporate customers.

Some of the philosophy of Unix:

+200

I have found Unix Power Tools to be one of the best resources for me. It may not have a tutorial in it, but it is a great reference.

I'm not necessarily looking for a tutorial anyway. :) I'd like something that's better as a reference tool. – Jason Baker Oct 25 '08 at 19:18

+1 - cribbed this for my post. – ConcernedOfTunbridgeWells Oct 26 '08 at 10:08

+150

The Art of Unix programming is a book that I've found helpful in the past, in spite of being a bit slanted against other non-unix platforms.

+110

The O'Reilly books have excellent *nix coverage. I have these:

Learning the bash Shell
* Covers several basic *nix command line tools as well as more advanced shell scripting techniques.

Learning the vi and Vim Editors
* Priceless. Gave me the ability to very quickly edit or create shell scripts, configuration files, Python scripts from the shell.

+100

I recommend the Armadillo book from O'Reilly for command line administration and shell scripting.

alt text

+1 - cribbed this for my post. – ConcernedOfTunbridgeWells Oct 26 '08 at 10:09

+70

Jason,

Unix Programming Environment by Kernighan and Pike will give you solid foundations on all things Unix and should cover most of your questions regarding shell command line scripting etc.

The Armadillo book by O'Reilly will add the administration angle. It has served me well!

Good luck!

+40

I can suggest the bunch of books here:

http://www.linux.org/docs/online_books.html

good luck;)

the link is broken – dbza Mar 7 '17 at 20:37

+40

The aforementioned Unix Power Tools is a must. Other classics are sed&awk and Mastering Regular Expressions. I also like some books from the O'Reilly "Cookbook" series:

+40

The Advanced Bash-Scripting Guide is the only book that really allows the reader to grok bash scripting. You need that ability to fully understand how to start/stop daemons and to automate a lot of tasks.

+20

The AWK Programming Language

Not only introduces to the versatile tool that awk is, but also gives an insight about the Unix based philosophy and some awk 'design-patterns'.

+20

alt text

In my opinion, you will learn more just by messing around with what you find interesting on a *nix box. It is a waste of time to read about BIND if you have no interest in networks.

why didnt my image post? img56.imageshack.us/img56/6668/0596005288500jx2.gif – theman_on_vista Dec 11 '08 at 17:01

Depends what you're doing. I've just got a fairly simple home network and I set up BIND to do internal name resolution. I've also got an email system dating back to UUCP days where I've been using Postfix since about 2000, smail from 1995-1999 and UUPC from 1991-1995. – ConcernedOfTunbridgeWells Dec 12 '08 at 12:07

NXC - thanks. Quick question - why not use /etc/hosts ? – theman_on_vista Dec 12 '08 at 14:10

Legacy systems - I have unix mailbox file archives going back to the 1990s and had a dial-up connection until 2002 or so. The network has a local MTA and DNS cache, although with a broadband connection these days you could probably just use the ones at the ISP. – ConcernedOfTunbridgeWells Dec 12 '08 at 21:49

+10

Big agreement for Essential System Adminstration and Unix Power Tools.

Also, whichever editor you prefer, vim or emacs, learn it back & forth. If you like vim, then get Steve Oualline's vim book.

+10

With regards to Ubuntu and Linux in general, a good book:

+10

Stephen Kochan's "Unix Shell Programming" and "Exploring the Unix System"

+10
  • sed & awk Dougherty and robbins
  • Mastering regular expression Jeffrey Friedl
  • Linux in a nutshell to look things up, although most of the info is also in manpages
  • Vim by Steve Oualline
0
votes
answers
35 views
+10

Linux不同的分佈命令

-2

嗨,我是Linux初學者,在閱讀Linux時,我發現三種類型的命令做同樣的工作服務,chkconfig,systemctl我知道這些是從分配到分配不同。任何人都可以建議如何學習這些命令的不同分配。Linux不同的分佈命令

尤其是如何記住:)

感謝

+1

歡迎使用[so],請在https://superuser.com/上發佈此問題...請閱讀[mcve],以便弄清楚哪些類型的問題屬於哪裏。這樣你會得到很好的答案。 –

沙发