📄 chap17.lst
字号:
listing 1
#include <process.h>
#include <conio.h>
int main(void)
{
for(;;)
if(getch()=='A') abort();
return 0;
}
listing 2
#include <stdio.h>
#include <stdlib.h>
/* Example using atexit(). */
int main(void)
{
void done();
if(atexit(done)) printf("Error in atexit().");
return 0;
}
void done()
{
printf("Hello there!");
}
listing 3
#include <stdio.h>
#include <stddef.h>
#include <process.h>
#include <conio.h>
void ThreadToRun(void *);
int main(void)
{
int i;
unsigned long thread;
for(i = 1; i < 10; i++)
{
thread = _beginthread(ThreadToRun, 4096, (void *)i);
if((long)thread == -1)
{
printf("Error creating thread number %d\n", i);
exit(1);
}
printf("Thread %d created with an ID of %uld.\n", i, thread);
}
printf("Press any key to exit...\n");
getch();
return 0;
}
void ThreadToRun(void *num)
{
printf("Running thread %d with an ID of %ld\n",
(int)num, _threadid);
_endthread();
}
listing 4
_cexit();
listing 5
/* First file - parent */
#include <stdio.h>
#include <process.h>
#include <stdlib.h>
int main(void)
{
execl("test.exe", "test.exe", "hello", "10", NULL);
return 0;
}
/* Second file - child */
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
printf("This program is executed with these command line ");
printf("arguments: ");
printf(argv[1]);
printf(" %d", atoi(argv[2]));
return 0;
}
listing 6
char menu(void)
{
char ch;
do {
printf("Enter names (E)");
printf("Delete name (D)");
printf("Print (P)");
printf("Quit (Q)");
} while(!strchr("EDPQ", toupper(ch)));
if(ch=='Q') exit(0);
return ch;
}
listing 7
#include <stdio.h>
#include <process.h>
#include <conio.h>
int main()
{
printf("This program PID = %d\n", getpid());
return 0;
}
listing 8
/* Parent process */
#include <stdio.h>
#include <process.h>
int main(void)
{
printf("In parent\n");
spawnl(P_WAIT, "test.exe", "test.exe", "hello", "10", NULL);
printf("In parent\n");
return 0;
}
/* First child */
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
int main(int argc, char *argv[])
{
printf("First child process executing ");
printf("with these command line arguments: ");
printf(argv[1]);
printf(" %d\n", atoi(argv[2]));
spawnl(P_WAIT, "test2.exe", "test2.exe", NULL);
printf("In first child process.\n");
return 0;
}
/* Second child */
#include <stdio.h>
int main(void)
{
printf("In second child process.\n");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -