⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 catch.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/unxagent/sun/catch.c,v 1.1.1.1 2001/11/05 17:49:16 tneale Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved.  Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** *  Copyright 1988-1997 Epilogue Technology Corporation. *  Copyright 1998 Integrated Systems, Inc. *  All rights reserved. ****************************************************************************//* * $Log: catch.c,v $ * Revision 1.1.1.1  2001/11/05 17:49:16  tneale * Tornado shuffle * * Revision 7.6  2001/01/19 22:25:00  paul * Update copyright. * * Revision 7.5  2000/03/17 00:15:14  meister * Update copyright message * * Revision 7.4  1998/02/25 04:58:17  sra * Update copyrights. * * Revision 7.3  1997/03/20 06:54:05  sra * DFARS-safe copyright text.  Zap! * * Revision 7.2  1997/02/25 10:58:16  sra * Update copyright notice, dust under the bed. * * Revision 7.1  1997/01/08 23:01:49  sar * Updated copyright and modified include files to use envoy/h as * appropriate * * Revision 7.0  1996/03/15  22:07:57  sar * Updated revision to 7.0 and copyright to 96 * * Revision 6.0  1995/05/31  21:49:41  sra * Release 6.0. * * Revision 5.0  1994/05/16  16:20:43  sar * Updated revision to 5.0 and copyright to include 1994 * * Revision 4.0  1993/06/24  17:34:02  sar * Updated rev to 4.0 copyright to 93 * * Revision 3.0  1992/04/03  19:53:44  dab * Release 3.0 * * Revision 2.100  92/02/03  16:46:04  dab * Generic unix SNMP agent. *  *  *    Rev 2.0   31 Mar 1990 15:34:18 * Initial revision. * *//* [clearcase]modification history-------------------01a,19apr05,job  update copyright notices*/#include <stdio.h>/*#include <stdlib.h>*/#include <memory.h>#define then#define LSIZE 512char buff[LSIZE];#define MAX_TTY		8#define MAX_CLINE	48typedef struct psdata_s	{	struct psdata_s *link;			unsigned int	pid;	unsigned int	ppid;	unsigned int	uid;	unsigned int	memsz;	unsigned int	cputime;	char		tty[MAX_TTY];	char		cmdline[MAX_CLINE];	} psdata_t;#define PS_DTA_NULL (psdata_t *)0psdata_t *ps_base = PS_DTA_NULL;psdata_t *ps_last = PS_DTA_NULL;main(argc, argv)     int argc; char **argv;{FILE *fp;int   index;psdata_t *curps;if ((fp = popen("ps -elf", "r")) == (FILE *)0)   then {        perror("Can't run ps");	exit(1);        }for(index = 0; ; index++)  {  int	bytes_got;  int	fields_got;  unsigned int hours, minutes;  if (fgets(buff, LSIZE, fp) == (char *)0) then break;  if (index == 0) then continue;  bytes_got = strlen(buff);/*  printf("I got %d: %s", bytes_got, buff);*/  buff[bytes_got-1] = '\0';	/* Remove the trailing newline */  if ((curps = (psdata_t *)malloc(sizeof(psdata_t))) == PS_DTA_NULL)     then {	  perror("Can not allocate memory to hold ps");	  exit(1);	  }  (void)memset((char *)curps, 0, sizeof(psdata_t));/*      F UID   PID  PPID CP PRI NI  SZ  RSS WCHAN    STAT TT  TIME COMMAND	 *//*   80011002   155   152  0   1  0 120  552 select   I    co  0:01 sunview -patt*//* The WCHAN field is sometimes blank */  fields_got =/*	 sscanf(buff, "%*7c%4u %u %u %*u %*u %*u %u %*u %*9c %*s %3s %2u%*1c%2u %48c",*/	 sscanf(buff, "%*7c%4u %u %u %*u %*u %*u %u %*u%*9c %*s %3s %2u%*1c%2u %48c",	     &(curps->uid), &(curps->pid), &(curps->ppid),	     &(curps->memsz), curps->tty, &hours, &minutes,	     curps->cmdline);  if (fields_got != 8)     then {#if 0	  printf("Skipping unusable ps record\n");  printf("got %d uid=%u  pid=%u  ppid=%u  memsz=%u  cpu=%u:%2.2u tty=%s cmd=%s#\n",	 fields_got,	     curps->uid, curps->pid, curps->ppid,	     curps->memsz, hours, minutes,	     curps->tty, curps->cmdline);#endif	  continue;	  }  curps->cputime = hours * 60 + minutes;  curps->link = PS_DTA_NULL;  if (ps_base == PS_DTA_NULL)     then {	  ps_base = curps;	  ps_last = curps;	  }     else {	  ps_last->link = curps;	  ps_last = curps;	  }  }(void)pclose(fp);for (index = 1, curps = ps_base;     curps != PS_DTA_NULL;     index++, curps = curps->link)   {  printf("index %d uid=%u  pid=%u  ppid=%u  memsz=%u  cpu=%u tty=%s cmd=%s#\n",	 index,	     curps->uid, curps->pid, curps->ppid,	     curps->memsz, curps->cputime,	     curps->tty, curps->cmdline);   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -