| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 616 人关注过本帖
标题:process函数的问题!
只看楼主 加入收藏
sunlee
Rank: 2
等 级:论坛游民
帖 子:77
专家分:15
注 册:2011-10-14
结帖率:70.59%
收藏
 问题点数:0 回复次数:0 
process函数的问题!
#include <windows.h>
#include <process.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <conio.h>

/* Macro to get a random integer within a specified range */
#define getrandom( min, max ) (( rand() % (int)((( max ) + 1 ) - ( min ))) + ( min ))

struct PROCESS
{

   int     nPid;
   char    name[40];

} process[4] = { { 0, "Ann" }, { 0, "Beth" }, { 0, "Carl" }, { 0, "Dave" } };

void main( int argc, char *argv[] )
{

   int termstat, c;

   srand( (unsigned)time( NULL ) );    /* Seed randomizer */
   /* If no arguments, this is the calling process */
   if( argc == 1 )
   {

      /* Spawn processes in numeric order */
      for( c = 0; c < 4; c++ ){
         _flushall();
         printf("hello,world!");
         process[c].nPid = spawnl( _P_NOWAIT, argv[0], argv[0],
                             process[c].name, NULL );
      }

      /* Wait for randomly specified process, and respond when done */
      c = getrandom( 0, 3 );
      printf( "Come here, %s.\n", process[c].name );
      _cwait( &termstat, process[c].nPid, _WAIT_CHILD );
      printf( "Thank you, %s.\n", process[c].name );

   }

   /* If there are arguments, this must be a spawned process */
   else
   {

      /* Delay for a period determined by process number */
      Sleep( (argv[1][0] - 'A' + 1) * 1000L );
      printf( "Hi, Dad. It's %s.\n", argv[1] );

   }
   _getch();
}

//按照微软的说法,应该是打印出来几组数据,但是在vs2010中,我只能够打印出来一组数据,这是为什么呢?麻烦谁说一下!
搜索更多相关主题的帖子: max specified process include 
2012-05-18 00:37
快速回复:process函数的问题!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025022 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved