如何在minix 3中打印正在运行的进程? [英] How do I print the running processes in minix 3?

查看:55
本文介绍了如何在minix 3中打印正在运行的进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <lib.h>    
#include <stdio.h>

int main(void) {
    int  nr_procs;
    printf("processes: %d\n",nr_procs);
    return 0;
}





我的尝试:



我试过这段代码,但结果我得到了:

流程:134244732

----------而是我必须取这个结果--------------

流程:112

你有什么想法为什么它打印我这个大号?



What I have tried:

I have tried this code but as a result i get:
processes: 134244732
----------but instead i have to take this result--------------
processes: 112
Have you have any ideas why it prints me this big number?

推荐答案

它打印了一个巨大的数字,因为你从未初始化nr_procs变量。它将是代码运行时为该变量分配的内存中发生的任何事情。

It prints a huge number because you never initialized the nr_procs variable. It'll be whatever happens to be in memory allocated for that variable when the code is run.
int nr_procs = 0;





您也从未试图从任何地方获取流程列表,所以我不知道您真正期望的是什么除了打印无意义的数字之外的其他代码。



You also never tried to get a list of processes from anywhere so I don't know what you really expect this code to do other than print a meaningless number.


引用:

您有什么想法吗?打印我这个大号?

Have you have any ideas why it prints me this big number?

是的,你的程序打印出你要求的内容,但是你提出错误。

Yes, your program print what you requested, but you requested wrong.

引用:

int  nr_procs;

在这里你声明一个未初始化的变量,你不在其中放入一个值,然后打印其中的随机值。

你忘了用变量提供变量。

你需要

Here you declare an uninitialized variable, you don't put a value in it, and then you print the random value that is in it.
You forgot to feed the variable with a value.
You need

int  nr_procs;
nr_procs= something;
printf("processes: %d\n",nr_procs);


这篇关于如何在minix 3中打印正在运行的进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆