Beispiel #1
0
int main(int argc, char *argv[]) {
  exitUnless(argc == 2, kWrongArgumentCount,
	     stderr, "Usage: %s <n>\n", argv[0]);
  size_t secs = atoi(argv[1]);  
  for (size_t i = 0; i < secs; i++) {
    sleep(1);
  }  
  pid_t pid = getpid(); 
  exitUnless(kill(-pid, SIGTSTP) == 0, kKillError,
	     stderr, "Failed to SIGSTP process group %d.\n", pid);
  return 0;
}
int main(int argc, char *argv[]) {
  exitUnless(argc == 3, stderr, kWrongArgumentCount, "Usage: %s <directory> <pattern>\n", argv[0]);
  struct stat st;
  const char *directory = argv[1];
  stat(directory, &st);
  exitUnless(S_ISDIR(st.st_mode), stderr, kDirectoryNeeded, "<directory> must be an actual directory, %s is not", directory);
  size_t length = strlen(directory);
  if (length > kMaxPath) return 0;

  const char *pattern = argv[2];
  char path[kMaxPath + 1];
  strcpy(path, directory); // no buffer overflow because of above check
  listMatches(path, length, pattern);
  return 0;
}
Beispiel #3
0
int main() {
#ifdef __linux
	const char* device = "/dev/ttyUSB3";
#endif
#ifdef RSSCON_WINDOWS
	const char* device = "COM:5";
#endif
	LOG4C_CATEGORY log = get_log(LOG_CATEGORY);

	log_info(log, "create rsscon");
	unsigned int baudrate = RSSCON_BAUDRATE_921600;
	Rsscon* rsscon = rssconCreate(device, baudrate);
	printErrorUnless(rsscon != NULL, "rsscon is null.");
	exitUnless(rsscon != NULL );

	log_info(log, "init rsscon");
	bool ret = rssconInit(rsscon);
	printErrorUnless(ret, "rsscon init.");
	printRssconError(rsscon);
	cleanupUnless(ret, rsscon);
	exitUnless(ret);

	ret = rssconSetBlocking(rsscon, true);
	ret = rssconSetWait(rsscon, false);

	log_info(log, "open rsscon");
	ret = rssconOpen(rsscon);
	printErrorUnless(ret, "rsscon open.");
	printRssconError(rsscon);
	cleanupUnless(ret, rsscon);

//	ret = readInfo(rsscon);
//	printErrorUnless(ret, "read info.");
//	printRssconError(rsscon);
//	cleanupUnless(ret, rsscon);

	log_info(log, "read data");
	ret = readData(rsscon);
	printErrorUnless(ret, "read data.");
	printRssconError(rsscon);
	cleanupUnless(ret, rsscon);

	free_log();
	return 0;
}
int main(int argc, char *argv[]) {
  pid_t children[kNumChildren];
  for (size_t i = 0; i < kNumChildren; i++) {
    children[i] = fork();
    exitIf(children[i] == -1, kForkFail, stderr, "Fork function failed.\n");
    if (children[i] == 0) exit(110 + i);
  }

  for (size_t i = 0; i < kNumChildren; i++) {
    int status;
    exitUnless(waitpid(children[i], &status, 0) == children[i],
	       kWaitFail, stderr, "Intentional wait on child %d failed.\n", children[i]);
    exitUnless(WIFEXITED(status) && (WEXITSTATUS(status) == (110 + i)),
	       kExitFail, stderr, "Correct child %d exited abnormally.\n");
  }

  return 0;
}
static void waitForChildProcess(pid_t pid) {
  exitUnless(waitpid(pid, NULL, 0) == pid, kWaitFailed,
	     stderr, "Error waiting in foreground for process %d to exit", pid);
}