私の友人は以下の割り当てを持っています。誰でも "C"でこれを行う方法を指導できます。すべてのプロセスリストをUIDのファイルに保存します
すべてのプロセスリストをファイルに保存し、すべてのプロセスをUIDで並べ替えるプログラムを作成します。例えば
:
./a.out processidlist.txt
それはprocessidlist.txtする情報を保存する必要があります。
このprocessidlist.txtでは、プロセスをUIDでソートする必要があります。
は、彼はあなたが迷惑なヘッダー
UID PID PPID C STIME TTY TIME CMD
をしたくない場合は、これらのライン上の
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *fp1, *fp2;
FILE *fp;
int status;
char path[1035];
fp1 = fopen(argv[1], "w");
if (! fp1)
{
printf("Error opening file %s\n", argv[1]);
}
/* Open the command for reading. */
fp = popen("ps -Af | sort -k1", "r");
if (fp == NULL) {
printf("Failed to run command\n");
exit;
}
/* Read the output a line at a time - output it. */
while (fgets(path, sizeof(path)-1, fp) != NULL) {
printf("%s", path);
fputs(path, fp1);
}
/* close */
pclose(fp);
fclose(fp1);
return 0;
}
なぜこのタグはC++ですか? –
[_he/she_は何を試していますか?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) –
彼は以下のコマンドで試しましたが、twork ps -A- o UID> outputfile – kobe