linux systemº¯ÊýʹÓÃÏê½â
Ïà¹Øº¯Êý
fork£¬execve£¬waitpid£¬popen
±íÍ·Îļþ
££i nclude<stdlib.h>
¶¨Ò庯Êý
int system(const char * string);
º¯Êý˵Ã÷
system()»áµ÷ÓÃfork()²úÉú×Ó½ø³Ì£¬ÓÉ×Ó½ø³ÌÀ´µ÷ÓÃ/bin/sh-c stringÀ´Ö´ÐвÎÊýstring×Ö·û´®Ëù´ú±íµÄÃüÁ´ËÃü>ÁîÖ´ÐÐÍêºóËæ¼´·µ»ØÔµ÷ÓõĽø³Ì¡£ÔÚµ÷ÓÃsystem()ÆÚ¼äSIGCHLD ÐźŻᱻÔÝʱ¸éÖã¬SIGINTºÍSIGQUIT ÐźÅÔò»á±»ºöÂÔ¡£
·µ»ØÖµ
=-1:³öÏÖ´íÎó
=0:µ÷Óóɹ¦µ«ÊÇûÓгöÏÖ×Ó½ø³Ì
>0:³É¹¦Í˳öµÄ×Ó½ø³ÌµÄid
Èç¹ûsystem()ÔÚµ÷ÓÃ/bin/shʱʧ°ÜÔò·µ»Ø127£¬ÆäËûʧ°ÜÔÒò·µ»Ø-1¡£Èô²ÎÊýstringΪ¿ÕÖ¸Õë(NULL)£¬Ôò·µ»Ø·ÇÁãÖµ>¡£ Èç¹ûsystem()µ÷Óóɹ¦Ôò×îºó»á·µ»ØÖ´ÐÐshellÃüÁîºóµÄ·µ»ØÖµ£¬µ«ÊÇ´Ë·µ»ØÖµÒ²ÓпÉÄÜΪ system()µ÷ÓÃ/bin/shʧ°ÜËù·µ»ØµÄ127£¬Òò´Ë×îºÃÄÜÔÙ¼ì²éerrno À´È·ÈÏÖ´Ðгɹ¦¡£
¸½¼Ó˵Ã÷
ÔÚ±àд¾ßÓÐSUID/SGIDȨÏ޵ijÌÐòʱÇëÎðʹÓÃsystem()£¬system()»á¼Ì³Ð»·¾³±äÁ¿£¬Í¨¹ý»·¾³±äÁ¿¿ÉÄÜ»áÔì³Éϵͳ°²È«µÄÎÊÌâ¡£
·¶Àý
££i nclude<stdlib.h>
main()
{
system(“ls -al /etc/passwd /etc/shadow”);
}
Ö´Ðнá¹û£º
-rw-r--r-- 1 root root 705 Sep 3 13 :52 /etc/passwd
-r--------- 1 root root 572 Sep 2 15 :34 /etc/shado
Àý2£º
char tmp[];
sprintf(tmp,"/bin/mount -t vfat %s /mnt/usb",dev);
system(tmp);
ÆäÖÐdevÊÇ/dev/sda1¡£
systemÔ´Âë
#include
#include
#include
#include
int system(const char * cmdstring)
{
pid_t pid;
int status;
if(cmdstring == NULL){
return (1);
}
if((pid = fork())<0){
status = -1;
}
else if(pid == 0){
execl("/bin/sh", "sh", "-c", cmdstring, (char *)0);
-exit(127); //×Ó½ø³ÌÕý³£Ö´ÐÐÔò²»»áÖ´ÐдËÓï¾ä
}
else{
while(waitpid(pid, &status, 0) < 0){
&nbs
Ïà¹ØÎĵµ£º
df ÊÇÀ´×ÔÓÚcoreutils Èí¼þ°ü£¬ÏµÍ³°²×°Ê±£¬¾Í×Ô´øµÄ£»ÎÒÃÇͨ¹ýÕâ¸öÃüÁî¿ÉÒԲ鿴´ÅÅ̵ÄʹÓÃÇé¿öÒÔ¼°Îļþϵͳ±»¹ÒÔصÄλÖá£
¾ÙÀý£º
[root@localhost beinan]# df -lh
Filesystem ÈÝÁ¿ ÒÑÓà ¿ÉÓà ÒÑÓÃ% ¹ÒÔصã
/dev/hda8 11G 6.0G 4.4G 58% /
/dev/shm 236M 0 236M 0% /dev/shm
/dev/sda1 56G 22G 35G 39% /mnt/sda1
......
Çì×£ Linux ³É¹¦ 10 Äê
Linux®¼¼Êõ¡¢¿ª·¢Ä£ÐͺÍÉçÇø¶¼¶Ô IT Òµ²úÉúÁËÖØÒªµÄÓ°Ï죬ÎÒÃÇÄÜ×öµÄ¾ÍÊÇÕ¾µ½Ò»±ß¿´¿´ÕâЩ£¬ºÜ¸ßÐËÓë
developerWorks Ò»Æð¶È¹ýÁ˵ÚÒ»¸ö 10 Äê¡£Linux ÍŶÓÒѾ½«ÕâЩ¶Ô Linux ²úÉúÖØ´óÓ°ÏìµÄÄÚÈÝÕûÀíµ½Ò»Æð¡£
¹ýÈ¥ 10 ÄêÀLinux ·¢ÉúÁËÌ«¶àµÄÊÂÇ飬ºÜÄÑÍêÕûµØÁгö¸Ã²Ù×÷ϵͳµ ......
1. Ç°ÑÔ
±¾ÎĽéÉÜlinuxÄÚºËÖÐһЩ³£ÓõÄÊý¾Ý½á¹¹ºÍ²Ù×÷¡£
2. Ë«ÏòÁ´±í(list)
linuxÄÚºËÖеÄË«ÏòÁ´±íͨ¹ý½á¹¹ struct list_headÀ´½«¸÷¸ö½ÚµãÁ¬½ÓÆðÀ´£¬´Ë½á¹¹»á×÷ΪÁ´±íÔªËؽṹÖеÄÒ»¸ö²ÎÊý£º
struct list_head {
struct list_head *next, *prev;
};
Á´±íÍ·µÄ³õʼ»¯£¬×¢Ò⣬ ......
ÔÚlinuxÏÂÃæ°²×°mysql£¬Ê×ÏàÒª¸ù¾Ý²Ù×÷ϵͳµÄ°æ±¾£¬Ñ¡Ôñ¶ÔÓ¦µÄmysqlµÄ°æ±¾£¬¹Ù·½ÍøÕ¾ÉÏÓзdz£Ã÷È·µÄ·ÖÀà
http://dev.mysql.com/downloads/
ÔÚÕâÀïÎÒʵÑéµÄ²Ù×÷ϵͳÊÇredhat linux
mysql ÓÃÁËÁ½¸ö°²×°°ü£¬Ò»¸öÊÇserver¶Ë£¬Ò»¸öÊÇclient,ÎÒÓõÄÊÇrpm°ü£¬°²×°µÄÖ¸Áî±È½Ï¼òµ¥¡£
MySQL-server-community-5.1.42-0.rhel4.i38 ......