2014年8月14日 星期四

開機自動打開console並執行程式 Root重開機&自動擷取顯示卡

Auto Search VGA Card Test Program
a. code
vga.c
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>

int main(void){
system("lspci |grep -i 'VGA' > VGAlist.txt");
int var,i,error;
pid_t childpid;
pthread_t tid;
double *pret;
FILE *pFILE,*fp;
char buffer[]={ '+','1','\n'};
char fail[]={ '+','0','\n'};
pFILE=fopen("record.txt", "a");
if(pFILE==NULL){
printf("open failure");
return 1;
}else{
printf("search \"Radeon HD 7550M\" \n");
system("grep -c -r 'Radeon HD 7550M' ./VGAlist.txt > time.txt"); //compare 'Radeon HD 7550M' between VGAlist.txt,then export to time.txt.  if "1" mean conform 1 times, if "0" mean NULL conform.
system("grep -c -r 'Radeon HD 7550M' ./VGAlist.txt");//show compare to screen
       
fp=fopen("time.txt","r");//open file time.txt,read first word
for (i=0;i<1;i++){
fscanf(fp,"%d",&var);
printf("%d \n",var);
}
if (var==1)
printf("Radeon HD 7550M ready\n");
if(var==0)
printf("can't find Radeon HD 7550M\n");
fclose(fp);
//remove("time.txt");
if (var==1) //1 acord ,export to record +1
fwrite(buffer,1,sizeof(buffer),pFILE);

if(var==0) //no acord ,export to record +0
fwrite(fail,1,sizeof(fail),pFILE);
}
sleep(20);//buffer time



/* if((error=pthread_create(&tid,NULL,thread_func,NULL))){
fprintf(stderr,"failed to join thread. %s\n",strerror(error));
return 1;
}
system("sudo reboot");
if((error=pthread_join(tid,NULL)))
fprintf(stderr,"Failed to join thread: %s\n",strerror(error));*/
system("sudo shutdown -r 0"); //設定重開機
fclose(pFILE);
return 0;
}
b.編譯
#gcc vga.c -o vga


產生檔案
record.txt   (+1表示每次比對有該Radeon HD 7550M顯示卡並紀錄一次)
+1
+1
+1
+1
+1
+1
+1
+1
+1


VGAlist.txt  (將搜尋到顯示卡列表)
00:02.0 VGA compatible controller: Intel Corporation 3rd Gen Core processor Graphics Controller (rev 08)
01:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Thames [Radeon HD 7550M/7570M/7650M]


開機自動登入root設定


a.啟動終端機:crtl+alt+t
輸入#sudo gedit /etc/lightdm/lightdm.conf


檔名 lightdm.conf
增加或修改下面
greeter-show-manual-login=true #顯示手動登錄頁面
allow-guest=false #不啟動訪客帳戶
autologin-user=root #設定root自動登錄


b.設定root帳號
#sudo passwd root
#提示輸入密碼
#再次輸入密碼


c.輸入#gnome-session-properties
點擊”加入” ,完成編輯並儲存
名稱:vga
指令:gnome-terminal -x bash -c "./vga"
開機啟動.png
設定值.png


d.設定完畢後,開機會自動登入root超級使用者 並打開終端機執行vga執行檔

沒有留言:

張貼留言