¾ðÊó²Ê³Ø¤ò³Ø¤ÖÂç³ØÀ¸¤¬¥×¥í¥°¥é¥ß¥ó¥°(C¸À¸ì,Java¤Ê¤É)¡¢¥Í¥Ã¥È¥ï¡¼¥¯¡¢»ñ³Ê»î¸³(¾ðÊó½èÍýµ»½Ñ¼Ô»î¸³,CCNA)¤Ê¤É¤Ë´Ø¤¹¤ëµ»ö¤ò½ñ¤¤¤Æ¤¤¤Þ¤¹¡£
UNIX¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò»È¤¤¡¢´Êñ¤Ê¥·¥§¥ë¤òC¸À¸ì¤Ç¼ÂÁõ¤·¤Æ¤ß¤Þ¤·¤¿¡£¸½»þÅÀ¤Ç¤Ï°Ê²¼¤Îµ¡Ç½¤·¤«È÷¤¨¤Æ¤¤¤Þ¤»¤ó¤¬¡¢º£¸åµ¡Ç½¤òÄɲ乤ëͽÄê¤Ç¤¹¡£
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>
#define MAX_ARGS 10
#define MAX_LEN 100
void child(int argc, char *argv[MAX_ARGS]);
int main()
{
int argc, n = 0;
int status;
char input[MAX_LEN], *argv[MAX_ARGS], *cp;
const char *delim = " \t\n"; /* ¥³¥Þ¥ó¥É¤Î¶èÀÚ¤êʸ»ú */
while (1) {
/* ¥×¥í¥ó¥×¥È¤Îɽ¼¨ */
++n;
printf("command[%d] ", n);
/* 1¹ÔÆÉ¤ß¹þ¤à */
if (fgets(input, sizeof(input), stdin) == NULL) {
/* EOF(Ctrl-D)¤¬ÆþÎϤµ¤ì¤¿ */
printf("Goodbye!\n");
exit(0);
}
/* ¶õÇò,¥¿¥Ö¶èÀÚ¤ê¤Ç¥³¥Þ¥ó¥ÉÎó¤Ëʬ³ä¤¹¤ë */
cp = input;
for (argc = 0; argc < MAX_ARGS; argc++) {
if ((argv[argc] = strtok(cp,delim)) == NULL)
break;
cp = NULL;
}
/* exit¥³¥Þ¥ó¥É¤¬ÆþÎϤµ¤ì¤ë¤È½ªÎ» */
if(strcmp(argv[0], "exit") == 0) {
printf("Goodbye!\n");
exit(0);
}
pid_t pid = fork();
if(pid == -1) {
/* fork()¤Ë¼ºÇÔ¤·¤¿ */
perror("fork");
exit(1);
} else if(pid == 0) {
/* »Ò¥×¥í¥»¥¹ */
child(argc, argv);
} else {
/* ¿Æ¥×¥í¥»¥¹ */
wait(&status);
}
}
}
void child(int argc, char *argv[MAX_ARGS]) {
execvp(argv[0], argv);
}
****@ubuntu-vm:~/work/os$ gcc -Wall s_shell.c
****@ubuntu-vm:~/work/os$ ./a.out
command[1] ls
#ex01.c# execlp0.c fileio1.c~ fileio4.c~ s_shell.c
a.out execve0.c fileio2.c foo system0.c
ex1.c execve0.c~ fileio2.c~ fork0.c wait0.c
ex1.c~ fileio0.c fileio3.c fork0.c~ wait0.c~
ex2.c fileio0.c~ fileio3.c~ hello.c
ex2.c~ fileio1.c fileio4.c httpget.c
command[2] cat hello.c
#include <stdio.h>
int main() {
printf("hello, world!\n");
return 0;
}
command[3] gcc -Wall hello.c
command[4] ./a.out
hello, world!
command[5] exit
Goodbye!
****@ubuntu-vm:~/work/os$
¤³¤Î¥×¥í¥°¥é¥à¤ÏÅ칩Âç¤Î¥×¥í¥°¥é¥ß¥ó¥°Âè»°(2007ǯÅÙ)¤È¤¤¤¦²ÊÌܤιֵÁ»ñÎÁ¤È¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ò»²¹Í¤Ë¤·¤Æºî¤ê¤Þ¤·¤¿¡£
| ¾Ü²òUNIX¥×¥í¥°¥é¥ß¥ó¥° | |
![]() | W.¥ê¥Á¥ã¡¼¥É ¥¹¥Æ¥£¡¼¥ô¥ó¥¹ W.Richard Stevens ÂçÌÚ ÆØÍº ¥Ô¥¢¥½¥ó¥¨¥Ç¥å¥±¡¼¥·¥ç¥ó 2000-12 Çä¤ê¾å¤²¥é¥ó¥¥ó¥° : 124773 ¤ª¤¹¤¹¤áÊ¿¶Ñ ![]() Amazon¤Ç¾Ü¤·¤¯¸«¤ë by G-Tools |
¥Æ¡¼¥Þ:UNIX/Linux - ¥¸¥ã¥ó¥ë:¥³¥ó¥Ô¥å¡¼¥¿ - ¥½¡¼¥·¥ã¥ë¥Ö¥Ã¥¯¥Þ¡¼¥¯:
![]()
Author:TBVector
»ä¤Î¥µ¥¤¥È
¥Ö¥Ã¥¯¥Þ¡¼¥¯¤ÈRSS
ͧã¤Î¥µ¥¤¥È
¤¢¤ï¤»¤ÆÆÉ¤ß¤¿¤¤
¤Ï¤Æ¤Ê¥ê¥ó¥°