資源簡(jiǎn)介
經(jīng)典的shell實(shí)驗(yàn), 實(shí)驗(yàn)內(nèi)容為實(shí)驗(yàn)一個(gè)unix下的簡(jiǎn)易的shell程序, 搞懂了這個(gè)程序?qū)τ趗nix下的sigal機(jī)制會(huì)有一個(gè)更深入的理解, CMU大學(xué)(卡耐基 梅隆大學(xué))經(jīng)典計(jì)算機(jī)課程實(shí)驗(yàn)之一, 里面含有實(shí)驗(yàn)完整內(nèi)容及其源程序, 還有詳細(xì)的解答過程, 很多國內(nèi)大學(xué)的計(jì)算機(jī)課程都選用此實(shí)驗(yàn)作為其課程設(shè)計(jì)之一!
代碼片段和文件信息
/*?
?*?myint.c?-?Another?handy?routine?for?testing?your?tiny?shell
?*?
?*?usage:?myint?
?*?Sleeps?for??seconds?and?sends?SIGINT?to?itself.
?*
?*/
#include?
#include?
#include?
#include?
#include?
#include?
int?main(int?argc?char?**argv)?
{
????int?i?secs;
????pid_t?pid;?
????if?(argc?!=?2)?{
fprintf(stderr?“Usage:?%s?\n“?argv[0]);
exit(0);
????}
????secs?=?atoi(argv[1]);
????for?(i=0;?i????????sleep(1);
????pid?=?getpid();?
????if?(kill(pid?SIGINT)?0)
???????fprintf(stderr?“kill?(int)?error“);
????exit(0);
}
評(píng)論
共有 條評(píng)論