20145224&20145238 《信息安全系統設計基礎》第二次實驗

20145224&20145238 《信息安全系統設計基礎》第二次實驗

課程:信息安全系統設計基礎

班級:1452

姓名:陳顥文 荊玉茗

學號:20145224 20145238

指導教師:婁嘉鵬

實驗日期:2016.11.10

實驗時間:10:00-12:30

實驗序號:2

實驗目的與要求:

1.熟悉 linux 開發環境,學會基於 S3C2410 的 linux 開發環境的配置和使用。linux

2.使用linux的armv4l-unknown-linux-gcc編譯,使用基於NFS方式的下載調試,瞭解嵌入式開發的基本過程。安全

3.正確使用鏈接線等實驗儀器,並注意保護實驗箱。實驗結束以後將實驗箱送回。多線程

實驗原理

一、在Linux PC上,利用arm-linux-gcc編譯器,可編譯出針對Linux ARM平臺的可執行代碼。函數

二、瞭解多線程程序設計的基本原理。學習

三、學習pthread庫函數的使用。測試

線程相關函數

線程建立函數:線程

int pthread_create (pthread_t * thread_id, __const pthread_attr_t * __attr,void *(*__start_routine) (void *),void *__restrict __arg)設計

得到父進程 ID:調試

pthread_t pthread_self (void)rest

測試兩個線程號是否相同:

int pthread_equal (pthread_t __thread1, pthread_t __thread2)

線程退出:

void pthread_exit (void *__retval)

等待指定的線程結束:

int pthread_join (pthread_t __th, void **__thread_return)

互斥量初始化:

pthread_mutex_init (pthread_mutex_t *,__const pthread_mutexattr_t *)

銷燬互斥量:

int pthread_mutex_destroy (pthread_mutex_t *__mutex)

再試一次得到對互斥量的鎖定(非阻塞) :

int pthread_mutex_trylock (pthread_mutex_t *__mutex)

鎖定互斥量(阻塞) :

int pthread_mutex_lock (pthread_mutex_t *__mutex)

解鎖互斥量:

int pthread_mutex_unlock (pthread_mutex_t *__mutex)

條件變量初始化:

int pthread_cond_init (pthread_cond_t *__restrict __cond,__const pthread_condattr_t *__restrict __cond_attr)

銷燬條件變量 COND:

int pthread_cond_destroy (pthread_cond_t *__cond)

喚醒線程等待條件變量:

int pthread_cond_signal (pthread_cond_t *__cond)

等待條件變量(阻塞) :

int pthread_cond_wait (pthread_cond_t *__restrict __cond, pthread_mutex_t *__restrict __mutex)

在指定的時間到達前等待條件變量:

int pthread_cond_timedwait (pthread_cond_t *__restrict __cond,pthread_mutex_t *__restrict __mutex, __const struct timespec *__restrict __abstime)

實驗內容與步驟

一、開發環境的配置同實驗一。

二、將實驗所需代碼02_pthread和03_tty拷貝到共享文件夾bc中

三、進入虛擬機,可經過ls命令查看所屬文件夾下的文件,確保所需文件拷貝成功

四、對於多線程相關的代碼,編譯時須要先添加-lpthread的庫,輸入如下命令,運行make產生 pthread 可執行文件

五、下載調試,進入超級終端,在xp環境的超級終端中將共享文件夾掛載好,創建開發板與虛擬機之間的通信,輸入命令/host/02_pthread/pthread運行可執行文件 pthread,觀察運行結果的正確性,運行程序最後一部分結果以下:

六、按照一樣的方法運行03_tty的可執行文件term, 若是在執行./term時出現下面的錯誤No such file or directory,能夠經過方法創建一個鏈接來解決,輸入命令ln –sf /dev/tts/0 /dev/ttyS0(注意空格和字母大小寫)

七、運行結果後半部分以下,可按ctrl+c終止

實驗體會

實驗二在實驗一配置完試驗環境後就完成的很快,只需添加使用多線程程序相關的庫,產生可執行文件後在超級終端中運行便可。

相關文章
相關標籤/搜索