escape
驱动老牛
驱动老牛
  • 注册日期2002-02-01
  • 最后登录2004-08-20
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1377回复:7

shell编程与linux编程的关系?

楼主#
更多 发布于:2003-03-24 18:15
疑问:
在使用C++编程的时候,经常找不到所需要的
function call。只好使用system或者popen来
调用shell命令。我这种编程方法是否不太正规?
请问是否shell编程本来就充当提供系统调用的功能吗?
h_love
驱动牛犊
驱动牛犊
  • 注册日期2001-08-20
  • 最后登录2003-03-26
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-03-24 18:21
同感,好多功能我没有试通。
还有加法,我死活没有试成功。
hometown
驱动大牛
驱动大牛
  • 注册日期2002-10-24
  • 最后登录2004-05-21
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2003-03-24 19:11
同感,好多功能我没有试通。
还有加法,我死活没有试成功。
把你的例子传上来, 可以吗?
How fair and how pleasant art thou, O love, for delights!This thy stature is like to a palm tree, and thy breasts to clusters of grapes.I said, I will go up to the palm tree, I will take hold of the boughs thereof: now also thy breasts shall be as clusters of the vine, and the smell of thy nose like apples;And the roof of thy mouth like the best wine for my beloved, that goeth down sweetly, causing the lips of those that are asleep to speak.
escape
驱动老牛
驱动老牛
  • 注册日期2002-02-01
  • 最后登录2004-08-20
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2003-03-25 09:05
shell命令的功能非常广泛,不过在程序中频繁
调用shell,是否会导致一些问题?比如,shell有好多种,
bash,kash,csh等等。如果系统默认的shell不同,会
导致程序出错。我编程时需要根据任何一个进程的可执行文件
名来获取进程ID,就只好用
popen(\"pidof *** \", \'r\');
来实现。改写ps命令源代码好像过于繁琐,
又苦于找不到其它c/c++库调用。
hometown
驱动大牛
驱动大牛
  • 注册日期2002-10-24
  • 最后登录2004-05-21
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2003-03-25 10:02
shell命令的功能非常广泛,不过在程序中频繁
调用shell,是否会导致一些问题?比如,shell有好多种,
bash,kash,csh等等。如果系统默认的shell不同,会
导致程序出错。我编程时需要根据任何一个进程的可执行文件
名来获取进程ID,就只好用
popen(\"pidof *** \", \'r\');
来实现。改写ps命令源代码好像过于繁琐,
又苦于找不到其它c/c++库调用。
 

在UNIX中, 一般获取系统的相关参数是通过/proc文件系统来得到的, 这用通常的C语言中的C库的一些函数就可以得到。 在C++中调用C函数只要加上
extern \"C\"{
   c function calls  
}
就可以了 :D
How fair and how pleasant art thou, O love, for delights!This thy stature is like to a palm tree, and thy breasts to clusters of grapes.I said, I will go up to the palm tree, I will take hold of the boughs thereof: now also thy breasts shall be as clusters of the vine, and the smell of thy nose like apples;And the roof of thy mouth like the best wine for my beloved, that goeth down sweetly, causing the lips of those that are asleep to speak.
escape
驱动老牛
驱动老牛
  • 注册日期2002-02-01
  • 最后登录2004-08-20
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2003-03-25 12:05
在UNIX中, 一般获取系统的相关参数是通过/proc文件系统来得到的, 这用通常的C语言中的C库的一些函数就可以得到。 在C++中调用C函数只要加上
extern \"C\"{
c function calls
}
就可以了


大概要用模式匹配,正则表达式之类的东西吧?

如果我想操作硬盘,或者其它硬件,除了考虑shell,还有其它
选择吗?我对这个问题也比较困惑,请大虾帮助一下。谢了!
hometown
驱动大牛
驱动大牛
  • 注册日期2002-10-24
  • 最后登录2004-05-21
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
6楼#
发布于:2003-03-25 12:32
[quote] 在UNIX中, 一般获取系统的相关参数是通过/proc文件系统来得到的, 这用通常的C语言中的C库的一些函数就可以得到。 在C++中调用C函数只要加上
extern \"C\"{
c function calls
}
就可以了


大概要用模式匹配,正则表达式之类的东西吧?

如果我想操作硬盘,或者其它硬件,除了考虑shell,还有其它
选择吗?我对这个问题也比较困惑,请大虾帮助一下。谢了! [/quote](1)不是做模式匹配, 你说的还是没有走出SHELL编程的范围。 而是象文件一样操作, 比如说你想找某个进程的PID, 可以先搜索/PROC文件系统, 找到该进程的名字, 然后根据其目录的名字就可以确定其进程号了。不过通常来说, 有的可执行程序同时在执行, 这样一个名字就可能对应了几个进程号, 用PIDOF也有这样的情况, 但可以通过更细致的处理来确定唯一的进程号, 这个时候用/proc就比较方便了。
(2)有个概念要说以下, 在unix中, 任何设备都是作为一个文件来处理的, 如在IDE0上的硬盘一般对应的文件是/dev/hda, 第一个分区就是/dev/hda1, 要操作设备, 只要象操作文件就可以了。
How fair and how pleasant art thou, O love, for delights!This thy stature is like to a palm tree, and thy breasts to clusters of grapes.I said, I will go up to the palm tree, I will take hold of the boughs thereof: now also thy breasts shall be as clusters of the vine, and the smell of thy nose like apples;And the roof of thy mouth like the best wine for my beloved, that goeth down sweetly, causing the lips of those that are asleep to speak.
hometown
驱动大牛
驱动大牛
  • 注册日期2002-10-24
  • 最后登录2004-05-21
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
7楼#
发布于:2003-03-25 12:35
[quote][quote] 在UNIX中, 一般获取系统的相关参数是通过/proc文件系统来得到的, 这用通常的C语言中的C库的一些函数就可以得到。 在C++中调用C函数只要加上
extern \"C\"{
c function calls
}
就可以了


大概要用模式匹配,正则表达式之类的东西吧?

如果我想操作硬盘,或者其它硬件,除了考虑shell,还有其它
选择吗?我对这个问题也比较困惑,请大虾帮助一下。谢了! [/quote](1)不是做模式匹配, 你说的还是没有走出SHELL编程的范围。 而是象文件一样操作, 比如说你想找某个进程的PID, 可以先搜索/PROC文件系统, 找到该进程的名字, 然后根据其目录的名字就可以确定其进程号了。不过通常来说, 有的可执行程序同时在执行, 这样一个名字就可能对应了几个进程号, 用PIDOF也有这样的情况, 但可以通过更细致的处理来确定唯一的进程号, 这个时候用/proc就比较方便了。
(2)有个概念要说以下, 在unix中, 任何设备都是作为一个文件来处理的, 如在IDE0上的硬盘一般对应的文件是/dev/hda, 第一个分区就是/dev/hda1, 要操作设备, 只要象操作文件就可以了。  [/quote](3)有些硬件可以直接操作, 这些都是一些接口简单的设备, 可参考这个论坛里的帖子 my system halted! why?
How fair and how pleasant art thou, O love, for delights!This thy stature is like to a palm tree, and thy breasts to clusters of grapes.I said, I will go up to the palm tree, I will take hold of the boughs thereof: now also thy breasts shall be as clusters of the vine, and the smell of thy nose like apples;And the roof of thy mouth like the best wine for my beloved, that goeth down sweetly, causing the lips of those that are asleep to speak.
游客

返回顶部