}
}
void *threadB(void *junk) {
while(1) {
pthread_mutex_lock(&mutex);
count += 1;
pthread_cond_wait(&cond,&mutex);/*解锁mutex,并等待cond改变*/
pthread_mutex_unlock(&mutex); }
22.在LInux系统下利用C语言编程,实现一个程序,该程序功能类似于一个简单的shell程序,其具体要求为:从标准输入读取输入的命令名/可执行文件名(要求用户输入的命令名和和可执行文件名为绝对路径,可以不考虑参数传递),以回车作为命令/可执行文件名输入的结束,然后创建子进程执行对应的命令/可执行文件,此时程序本身不再进行任何操作直到当前命令/可执行文件执行结束为止;该程序一次只执行一条命令/可执行文件,不需要考虑输入输出重定向和管理,不需要考虑信号处理。 }
#include
int main(int argc,char *argv[]){
if(argc < 2){ }
pid_t pid; int status;
if((pid = fork())<0){ }
if(pid = 0){
execl(\ exit(0);
printf(\return 0;
printf(\return 0;
}else{ } return 0;
waitpid(pid, &status, 0);
}
23.在Linux系统下利用C语言编程,实现一个程序,该程序可以实现ls -l 命令的功能。(要求给出C语言代码或者给出关键代码并通过流程图及描述代码结构)。 #include \#include \#include \#include \#include \
void print_error(char *errmsg) { }
char *getformattime(time_t t) printf(\exit(0);
{ }
char *getuserinfo(uid_t my_uid) {
struct passwd *my_info; struct group *grp; static char userinfo[200]; char username[100]; char groupname[100]; static char formattime[20];
struct tm *lt; lt = localtime(&t); char tmptime[24];
memset(tmptime, 0, sizeof(tmptime));
strftime(tmptime, 24, \
strcpy(formattime,tmptime); return formattime;
}
my_info = getpwuid(my_uid); strcpy(username,my_info->pw_name);
grp = getgrgid(my_info->pw_gid); if (!grp){
strcpy(groupname,\
}else{ }
strcat(username,\strcat(username,groupname); strcpy(userinfo,username);
strcpy(groupname,grp->gr_name);
return userinfo;
char *getinfo(char *path) {
static char str[1000];
struct stat info; stat(path,&info);